C#中使用split分割字符串的几种方法小结
原文链接:https://www.jb51.net/article/34535.htm
static void Main(string[] args) { string str = "abcdeabcdeabcde"; //1、以一个指定的字符进行的分割 string[] strArray = str.Split('c'); foreach (string i in strArray) { Console.WriteLine(i.ToString()); } //2、使用另一种构造方法对多个字符进行分割 string[] strArrayOne = str.Split(new char[3] { 'c', 'd', 'e' }); foreach (string i in strArrayOne) { Console.WriteLine(i.ToString()); } //3、使用正则表达式,先添加 using System.Text.RegularExpressions; string content = "agcsmallmacsmallgggsmallytx"; string[] resultString = Regex.Split(content, "small", RegexOptions.IgnoreCase); foreach (string i in resultString) { Console.WriteLine(i.ToString()); } Console.ReadKey(); }