Newbie question.. Splitting a string value



I have a string separated by commas like this:


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

Newbie her

John M Deal

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question