一、分割拆分

1、使用字符分割:

(1)str.Split(','): // 按,分割str

2、使用字符组分割:

(1)str1=str.Split(new[] { '1','a' }, StringSplitOptions.None)[1];  // 按1ada分割str,取分割后集合的第二个值

3、使用字符串分割:

(1)str.Split("abc");  // 按abc分割str;core以上使用

(2)Regex.Split(floatsAddressStr,"\r\n");  // netframework使用

4、使用字符串分割:

(1)str1=str.Split(new[] { "1ada","adf" }, StringSplitOptions.None)[1];//按1ada分割str,取分割后集合的第二个值

二、是否包含指定字符

  str1.indexOf(str2) :str1包含str2

三、取值

(1)Regex.Match(str1, "(?<=str1).*?(?=str2")").Value;  // 

(2)Regex.Match(str1, "(?<=str1)[\s\S]*?(?=str2")").Value;  // 

(3)Regex.Matchs(str1, "(?<=str1).*?(?=str2")").Value;  // 

1、示例:

string str="( [ 1486, 427 ][ 流水号: ][ 0.977335 ])( [ 2271, 287 ][ 1/1 ][ 0.994448 ])"

  ① Match示例:Regex.Match(str1, "(?<=流水号:).*?(?=\")").Value;  // 页码
  ② Matches示例:cWSL.NumberOfPages = Regex.Matches(str1, @"(?<=\[).*?(?=\/)")[0].ToString()+ Regex.Matches(str1, @"(?<=\[).*?(?=\/)")[0].ToString();  // 页码

2、教程一:C#截取两个关键字之间的字符串
3、教程二:C# 截取字符串方法总结

四、去除指定字符串:

1、教程一:字符串中去除指定字符


作者:꧁执笔小白꧂