Learn how to a build a cloud-first strategyRegister Now


split a string and loop through array

Posted on 2007-07-27
Medium Priority
Last Modified: 2010-04-15
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?
Question by:mitesh114
  • 2
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 1000 total points
ID: 19581493
string data = "w1;w2;s3;s4";
string[] c = data.Split(';');
foreach ( string i in c )
{  // handle i
LVL 20

Expert Comment

ID: 19581504
personally I would use

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

as it it faster than the string Split method.

Andrew :-)

Expert Comment

ID: 19581814
> 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...
LVL 20

Expert Comment

ID: 19581967
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.




Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question