Getting data from string

  • Thread starter Thread starter J
  • Start date Start date
J

J

I have a string with lots of numbers i need in a seperate
an array. each number is split using a ",". How do i
split them up and put them in to an array.

eg.
egstring = 1,23,423,2,2

i need to get the numbers
1
23
423
2
2
and then add them to an array.

thanks for any help in advance. J
 
J said:
I have a string with lots of numbers i need in a seperate
an array. each number is split using a ",". How do i
split them up and put them in to an array.

eg.
egstring = 1,23,423,2,2

i need to get the numbers
1
23
423
2
2
and then add them to an array.

Dim arrInteger as Integer()

arrInteger = Split(egString,",")

That should do it.
 
Hello,

J said:
I have a string with lots of numbers i need in a seperate
an array. each number is split using a ",". How do i
split them up and put them in to an array.

eg.
egstring = 1,23,423,2,2

i need to get the numbers
1
23
423
2
2
and then add them to an array.

\\\
Dim s As String = "1,23,423,2,2"
Dim astr() As String = s.Split(","c)
///

- or -

\\\
Dim s As String = "1,23,423,2,2"
Dim astr() As String = Strings.Split(s, ",")
///
 
I believe Split() returns a string array so your code would generate an
invalid type exception. If you need it in an integer array, you'll have to
put it in a string array temporarily and loop through the array and stuff it
into a new integer array. Or you can leave it in the string array and
perform any conversions on the fly.
 
I believe Split() returns a string array so your code would generate
an invalid type exception. If you need it in an integer array, you'll
have to put it in a string array temporarily and loop through the
array and stuff it into a new integer array. Or you can leave it in
the string array and perform any conversions on the fly.


Oops, you're correct!
 
Back
Top