/// <summary> /// 找出子字符串在字符串中的所有索引,"ccc"在"ccccc"中认为只有一个 /// </summary> /// <param name="str"></param> /// <param name="subStr"></param> /// <returns></returns> private static List<int> AllIndexOf(string str, string subStr) { List<int> li = new List<int>(); var i = 0; i = str.IndexOf(subStr, StringComparison.Ordinal); while (i != -1) { li.Add(i); i = str.IndexOf(subStr, i + subStr.Length, StringComparison.Ordinal); } return li; }