Reputation: 5124
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?
Upvotes: 13
Views: 11767
Reputation: 837926
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
Upvotes: 6
Reputation: 3214
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.
Upvotes: 21
Reputation: 8053
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?
Upvotes: 1