string str = "1,2,3,4,5,6";
怎么计算此字符串中逗号的个数?

方法1:
string str = "1,2,3,4,5,6";
int count = str.Count(ch => ch == ',');
//count=5

方法2:
str.Split(',').Length-1

方法3:
string str = "1,2,3,4,5,6";
int count = str.Length - str.Replace(",", "").Length;

方法4:
Regex.Matches(str,@",").Count

方法5:
str.ToCharArray().Where(x=x.Equals(',')).ToArray().length

 

相关文章:

  • 2022-01-08
  • 2022-12-23
  • 2022-01-27
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2020-04-08
  • 2021-07-25
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案