By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,579 Members | 1,765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,579 IT Pros & Developers. It's quick & easy.

Getting data from string

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"J" <no@spam> wrote in news:0c****************************@phx.gbl:
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.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #2

P: n/a
Hello,

"J" <no@spam> schrieb:
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, ",")
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3

P: n/a
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.
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"J" <no@spam> wrote in news:0c****************************@phx.gbl:
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.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 20 '05 #4

P: n/a
"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in
news:Oe**************@TK2MSFTNGP09.phx.gbl:
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!
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #5

P: n/a
J
thanks for all your help :o)
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.