C# 統計字串出現的個數
阿新 • • 發佈:2018-11-07
string str1 = "123AAA456AAAA789AAAAAAA1011"; string str2 = "123456789AAA23456789AAAA3456789AAAAAAA4567890"; string str3 = "123456788AAA23456789AAAA3456789AAAAAAA4567890"; string str4 = "123456788AAA0AAAA0AAAAAAA"; var strArry = (str1 + "&" + str2 + "&" + str3 + "&" + str4).Split('&'); //把字串連線為陣列 char[] str1Arry = str1.ToArray(); int js = 0; List<int> TempArry = new List<int>(); for (int i = 0; i < str1Arry.Length; i++) { if (str1Arry[i] == 'A') { js++; continue; } if (js != 0) //找到A, 不等於A時候執行 { TempArry.Add(js); js = 0; //js歸0 } }