1.统计一个字符串在字符串中出现的次数
例如:查找“this”在目标字符串中出现的次数
string a = "thisismythis"; int count1 = (a.Length - a.Replace("this", "").Length) / "this".Length;
结果为:2
2.用字符串分割字符串
例如:用“this”将字符串分割成数组
string a = "thisismythis"; string[] strArr = a.Split(new[] { "this" }, StringSplitOptions.None);
结果为:["","ismy",""]
3.用某个字符分割字符串
例如:用“|”将字符串分割成数组,并移除空元素
string str = "01|25||26|"; string[] strArray = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
结果为:["01","25","26"]