1.C#String.IndexOf检索字符串中字符出现的次数

string str = "Hello, please come to my office the afternoon";
string s = "o";
int Star = 0;
int Count = 0;

while (Star != -1)
{
Star = str.IndexOf(s, Star);//获取字符的索引
if (Star != -1)
{
Count++;
Star++;
}
}
Console.WriteLine(Count.ToString());
Console.ReadKey();

注:本文整理自网络!!!

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-22
  • 2022-01-02
  • 2021-07-04
  • 2022-12-23
  • 2021-10-29
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案