Regex r = new Regex(childstr);
str = r.Replace(str, "", 1);
应用:已知一个字符串,比如asderwsde,寻找其中的一个子字符串比如sde 的个数,如果没有返回0,有的话返回子字符串的个数。
public static int getnum(string str,string childstr)
{
int num = 0;
if (str == "" || childstr == "")
{
return num;
}
while (str.IndexOf(childstr) > 0)
{
Regex r = new Regex(childstr);
str = r.Replace(str, "", 1);
num++;
}
return num;
}
来自:https://blog.csdn.net/qq_33380252/article/details/107941469
标签:Regex,C#,childstr,int,num,str,字符串,替换 From: https://www.cnblogs.com/east115/p/16637193.html