本文介绍了分割字符串与多个字符在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过ER分隔符来分割字符串=Asaf_ER_Army。 字符串分割函数不允许拆分由多个字符的字符串。
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?
推荐答案它。阅读 href=\"msdn.microsoft/en-us/library/tabh47cf.aspx\">。
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);
编辑:或者,你可以有一些更复杂的选择(正则表达式)。在这里, dotnetperls/string-split 。
更多推荐
分割字符串与多个字符在C#
发布评论