分割字符串与多个字符在C# [英] split string with more than one Char in C#

查看:112
本文介绍了分割字符串与多个字符在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=\"http://msdn.microsoft.com/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);



编辑:
或者,你可以有一些更复杂的选择(正则表达式)。在这里, http://dotnetperls.com/string-split

这篇关于分割字符串与多个字符在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆