using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 字符串中截取b的数量 { class Program { static void Main(string[] args) { int i = 0; Console.WriteLine("请输入:"); string B = Console.ReadLine(); B = B.ToLower(); if (B.IndexOf("b") < 0) { Console.WriteLine("没有b"); } else { int c = B.Length; for (i = 0; i <= c; i++) { int b = B.IndexOf("b"); if (b < 0) break; B = B.Substring(b + 1); } Console.WriteLine("字符中含有" + i + "个b(B)"); } Console.ReadLine(); } } }