开发者

split string with more than one Char in C#

开发者 https://www.devze.com 2023-01-19 14:20 出处:网络
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.

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?


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.


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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消