split a string and loop through array

hi, i have a string like this: w1;w2;s3;s4.

I want to split this string and store each item in an array and then be able to loop through the array.  How would I do this?
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
string data = "w1;w2;s3;s4";
string[] c = data.Split(';');
foreach ( string i in c )
{  // handle i
personally I would use

string[] c = System.Text.RegularExpressions.Regex.Split(";","YourInput");

as it it faster than the string Split method.

Andrew :-)
> as it it faster than the string Split

do you have a reference that demonstrates that Regex.Split is faster - the sources I have seen say that Regex.Split is significantly *slower* than string.split (even with a compiled regex) - I guess because the functionality behind it is much more complex...
I stand corrected lol

My evidence came from a past project I did. But you have prompted me to look at the theory nehind it, and as I say I stand corrected.



Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.