C#如何用正则表达式计算字符串的个数

C#如何用正则表达式计算字符串的个数
2025-05-12 23:23:52
推荐回答(2个)
回答1:

String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}

回答2:

你的要求的字符串是什么? 纯数字还是字符?

如下示例说明了怎么在str中找出,号的数量
var str = "aaa,bb,cc,dd,ee,sa1,ewe";
Regex regex = new Regex(@"(\,)");
int count = regex.Matches(str).Count;