分割字符串与多个字符在C#

编程入门 行业动态 更新时间:2024-10-28 10:33:28
本文介绍了分割字符串与多个字符在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#

本文发布于:2023-11-02 18:10:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   字符串   字符

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!