Console.WriteLine("请输入字符"); string a = Console.ReadLine(); string A=a.ToLower(); Console.WriteLine("请输入您想要查找的字符"); string b = Console.ReadLine(); string B=b.ToLower(); bool c = a.Contains(B); int x = a.Length, y = 0, m , n ; if (c) { for ( m = 0; m < x; m++) { n = A.IndexOf(B, m);//B是索引值,k是索引的起始位置 if ( n == m) y++; } Console.Write("您输入的字符中包含" + y + "个"+B); } else Console.Write("您输入的字符中不包含"+ B); Console.ReadLine();