C#如何判断一个标点符号在字符串中出现的次数?????

2024-12-21 10:25:20
推荐回答(2个)
回答1:

string s = "a,b,,";
string[] t = s.Split(',');
MessageBox.Show((t.Length-1).ToString());结果为3

回答2:

很简单:
string s = "asdegnri,e,wgbiergb,kjw,,eq,f";
int i = s.Count(c => c == ',');
Console.WriteLine(i);