Home All Groups Group Topic Archive Search About

Splitting a string array to seperate variables

Author
4 Apr 2005 4:11 PM
JeffM
Quick C# question:
I have comma delimited values in a string array that I want to pass to
seperate variables. Any tips on splitting the array?

Thanks in advance!

JM



*** Sent via Developersdex http://www.developersdex.com ***

Author
4 Apr 2005 4:23 PM
Alex Passos
First thing that comes to mind is the string Split method:

string csv = "1,2,3,4";
string [] numbers = csv.Split(",".ToCharArray());

Here is the MSDN docs and samples to do this:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssplittopic.asp

Alex

Show quoteHide quote
"JeffM" <Je***@devdex.com> wrote in message
news:O1TDDETOFHA.2704@TK2MSFTNGP15.phx.gbl...
> Quick C# question:
> I have comma delimited values in a string array that I want to pass to
> seperate variables. Any tips on splitting the array?
>
> Thanks in advance!
>
> JM
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Are all your drivers up to date? click for free checkup

Author
4 Apr 2005 9:28 PM
JeffM
Thanks Alex!
Just what I was looking for-



*** Sent via Developersdex http://www.developersdex.com ***
Author
4 Apr 2005 7:58 PM
William Stacey [MVP]
If you also want to split quoted fields and/or ignore multiple delim in a
row, check out:
http://spaces.msn.com/members/staceyw/Blog/cns!1pnsZpX0fPvDxLKC6rAAhLsQ!352.entry

--
William Stacey, MVP
http://mvp.support.microsoft.com

Show quoteHide quote
"JeffM" <Je***@devdex.com> wrote in message
news:O1TDDETOFHA.2704@TK2MSFTNGP15.phx.gbl...
> Quick C# question:
> I have comma delimited values in a string array that I want to pass to
> seperate variables. Any tips on splitting the array?
>
> Thanks in advance!
>
> JM
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
4 Apr 2005 9:35 PM
JeffM
Wow, that's a pretty cool script.
Although I am generating test files out of Excel, so spacing and
formatting should be OK, this is very nice to allow commas in the input
string itself.
Thanks much :-)

JM



*** Sent via Developersdex http://www.developersdex.com ***

Bookmark and Share