Newbie question.. Splitting a string value

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

john

I have a string separated by commas like this:

I,am,Sam,he,is,Tom,She,is,Mary

How do I split this string into individual string values(the separation
parameter being the comma). In short, I want the result to be:

string1 = I
string2 = am
string3= Sam
string4= he
etc.

thanks
Newbie her
 
The string object containing your string text has a built in split
method. So if you had:

string sentences = "I,am,Sam,he,is,Tom,She,is,Mary";

you could split this into an array of values like:

string[] splitArray = sentences.Split(',');

You can then get to each value by index:

string string1 = splitArray[0];
....

You can also us a foreach construct on the array.

Have A Better One!

John M Deal, MCP
Necessity Software
 
Back
Top