我想通過「ER」分隔符分割String =「Asaf_ER_Army」。 String的Split函數不允許將字符串拆分多個char。在C中有多個Char的分割字符串
我如何通過'多個char'分隔符來分割字符串?
我想通過「ER」分隔符分割String =「Asaf_ER_Army」。 String的Split函數不允許將字符串拆分多個char。在C中有多個Char的分割字符串
我如何通過'多個char'分隔符來分割字符串?
它確實。閱讀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);
編輯: 或者,你可以有一些更復雜的選擇(正則表達式)。這裏,http://dotnetperls.com/string-split。
String.Split
做你想做的。使用接受字符串數組的重載。
實施例:
string[] result = "Asaf_ER_Army".Split(
new string[] {"ER"},
StringSplitOptions.None);
結果:
Asaf_ _Army
有這需要一個字符串數組作爲分隔String.Split的過載:http://msdn.microsoft.com/en-gb/library/1bwe3zdy%28v=VS.80%29.aspx
除非使用框架< 2?