//統(tǒng)計(jì)某個(gè)字符串中指定字符串出現(xiàn)的次數(shù) 用string.Split()方法實(shí)現(xiàn) static void CountChar() { Console.WriteLine("請輸入一個(gè)字符串:"); string s = Console.ReadLine(); Console.WriteLine("請輸入要查詢的子字符串:"); string[] sub ={Console.ReadLine()}; string[] arr = s.Split(sub,StringSplitOptions.None); Console.WriteLine("{0}出現(xiàn)的次數(shù)為:{1}",sub[0],arr.Length-1); }
|
|