tags:

views:

84

answers:

3

i want to split the String = "Asaf_ER_Army" by the "ER" seperator. the Split function of String doesn't allow to split the string by more than one char.

how can i split a string by a 'more than one char' seperator?

+2  A: 

string.Split does do what you want. Use the overload that takes a string array.

Example:

string[] result = "Asaf_ER_Army".Split(new string[] {"ER"}, StringSplitOptions.None);

Result:

Asaf_
_Army
Mark Byers
+9  A: 

It does. Read here.

string source = "[stop]ONE[stop][stop]TWO[stop][stop][stop]THREE[stop][stop]";
string[] stringSeparators = new string[] {"[stop]"};

// Split a string delimited by another string and return all elements.
string[] result = source.Split(stringSeparators, StringSplitOptions.None);

Edit: Alternately, you can have some more complicated choices (RegEx). Here, http://dotnetperls.com/string-split.

Nayan
A: 

There is an overload of String.Split which takes a string array as separators: http://msdn.microsoft.com/en-gb/library/1bwe3zdy%28v=VS.80%29.aspx

Unless you are using framework < 2?

GôTô