Dear all,
I am wondering, that I can't find how to delete an element from an array.
dim a as string()
a=SomeString.split(",")
for ...
if _string="" then a.delete????
... 10 1060
"Boni" <oilia@nospam> schrieb: I am wondering, that I can't find how to delete an element from an array. dim a as string() a=SomeString.split(",")
for ... if _string="" then a.delete????
You'll have to create a new array of appropriate size and copy over the
items of the original array to the new array using 'Array.Copy' or
'Array.CopyTo'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
It is ugly. Is there no better solution? If split(.) returns an array I
can't take other collection type. Is it really nothing more appropriate?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP10.phx.gbl... "Boni" <oilia@nospam> schrieb: I am wondering, that I can't find how to delete an element from an array. dim a as string() a=SomeString.split(",")
for ... if _string="" then a.delete????
You'll have to create a new array of appropriate size and copy over the items of the original array to the new array using 'Array.Copy' or 'Array.CopyTo'.
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
You can't 'delete' an element from the middle of an array. You need to use a
collection for that functionality, or run through your array, copying all non
blank elements into another array.
"Boni" wrote: Dear all, I am wondering, that I can't find how to delete an element from an array. dim a as string() a=SomeString.split(",")
for ... if _string="" then a.delete???? ...
"Boni" <oilia@nospam> schrieb It is ugly. Is there no better solution? If split(.) returns an array I can't take other collection type. Is it really nothing more appropriate?
In addition the other answers: You can't delete an item because you would
have to quarry out a piece of your RAM module. Sounds funny but that's how
it is. Just like you can't delete a line from a text file on your HD. You
have to overwrite it by the subsequent lines (or array elements). As the
length of an array is fixed, there would be one remaining ununsed item at
the end. To solve the problem, the whole array must be copied into a new
array - without the item to be deleted. The same is done by Redim Preserve
BTW.
Armin
"Boni" <oilia@nospam> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... Dear all, I am wondering, that I can't find how to delete an element from an array.
I'd suggest constucting an ArrayList from the String array :
Dim a As New ArrayList( SomeString.Split(","c) )
For iIdx as Integer = a.Count - 1 To 0 Step -1
If False Then
a.RemoveAt( iIdx )
End if
Next
HTH,
Phill W.
Boni wrote: Dear all, I am wondering, that I can't find how to delete an element from an array. dim a as string() a=SomeString.split(",")
for ... if _string="" then a.delete???? ..
There is another option, you can use arraylist to do the removing for you.
dim Str() as string
dim Arr as new ArrayList(str.split(","))
for ii as integer = 0 to Arr.Count-1
if cstr(Arr(ii)).length = 0 then Arr.Remove(ii)
Next
Chris
I think you would find it quicker to dim another array the same size of array
"a" then copy only the non blank elements to the new array and count them.
Then redim preserve the new array to the count of non items, i.e.
dim b(a.upperbound) as string
dim count as integer =0
for i as integer= 0 to a.upperbound
if a(i) <>"" then
b(count)=a(i)
count = count+1
end if
next
redim preserve b(count-1)
--
Dennis in Houston
"Boni" wrote: Dear all, I am wondering, that I can't find how to delete an element from an array. dim a as string() a=SomeString.split(",")
for ... if _string="" then a.delete???? ... In addition the other answers: You can't delete an item because you would have to quarry out a piece of your RAM module
Was it a joke? I did it and my PC is dead now! :)
Thank you all. ArrayList is what I was looking for:)
"Chris" <no@spam.com> schrieb im Newsbeitrag
news:eP**************@TK2MSFTNGP10.phx.gbl... Boni wrote: Dear all, I am wondering, that I can't find how to delete an element from an array. dim a as string() a=SomeString.split(",")
for ... if _string="" then a.delete???? ..
There is another option, you can use arraylist to do the removing for you.
dim Str() as string dim Arr as new ArrayList(str.split(","))
for ii as integer = 0 to Arr.Count-1 if cstr(Arr(ii)).length = 0 then Arr.Remove(ii) Next
Chris
"Boni" <oilia@nospam> schrieb
In addition the other answers: You can't delete an item because you would have to quarry out a piece of your RAM module Was it a joke? I did it and my PC is dead now! :)
Sorry, forgot the smiley. ;-)
Armin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Roy Riddex |
last post by:
2nd post of the day! I'm just learning about Arrays at College and have met
a problem. I have 5 text boxes for number input, a command button to add the
numbers to the array, and a command button...
|
by: da Vinci |
last post by:
OK, this has got to be a simple one and yet I cannot find the answer
in my textbook.
How can I get a simple pause after an output line, that simply waits
for any key to be pressed to move on?
...
|
by: jmac |
last post by:
Greetings fellow programmers,
I have created a C program that has a few bugs and would like to get
some help with working them out. Here is a list of the problems that
I am experiencing:
-...
|
by: Alan |
last post by:
hi all,
I want to define a constant length string, say 4
then in a function at some time, I want to set the string to a constant
value, say a
below is my code but it fails
what is the correct...
|
by: Ross A. Finlayson |
last post by:
I'm trying to write some C code, but I want to use C++'s std::vector.
Indeed, if the code is compiled as C++, I want the container to
actually be std::vector, in this case of a collection of value...
|
by: niclane |
last post by:
Hi,
I was reading section 5.5 of Ritchie and Kernighan and saw the
following:
"
.....
char amessage = "now is the time";
char *pmessage = "now is the time";
|
by: NewInTheGame |
last post by:
I'm a beginner in VB.Net. I'm actually taking a class & so far I
understand everything, but I suck when it comes to arrays. I'm sure
that this is simple (I'm ashamed of asking :oops: )...
I...
|
by: Claudio Grondi |
last post by:
In the process of learning about some deeper details of Python I am
curious if it is possible to write a 'prefix' code assigning to a and b
something special, so, that Python gets trapped in an...
|
by: learnfpga |
last post by:
Here is a little code I wrote to add the numbers input by the
user.....I was wondering if its possible to have the same functionality
without using dynamic arrays.....just curious.....
...
|
by: Michael |
last post by:
Hi,
I am trying to pass a function an array of strings, but I am having trouble
getting the indexing to index the strings rather than the individual
characters of one of the strings.
I have...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |