Josh
Josh

Reputation: 1911

How can I add stringbuilder (semi colon delimited) values to arraylist in C#?

I have a stringbuilder that will look like something close to this smith;rodgers;McCalne etc and I would like to add each value to an arraylist. Does anyone have any C# code to show this?

many thanks

Upvotes: 3

Views: 1956

Answers (3)

vodkhang
vodkhang

Reputation: 18741

string s = "smith;rodgers;McCalne";
//
// Split string on spaces.
// ... This will separate all the words.
//
string[] words = s.Split(";");
var a = new ArrayList<String>();
foreach (string word in words)
{
    a.add(word);
}

An example is here

Upvotes: 2

remi bourgarel
remi bourgarel

Reputation: 9389

myArray.AddRange(myStringBuilder.ToString().Split(';'))

That's it

Upvotes: 11

Matt Greer
Matt Greer

Reputation: 62057

myStringBuilder.ToString().Split(';').ToList()

Upvotes: 7

Related Questions