1.string.IndexOf()方法可以获得第一个匹配项的索引
2.要获取第n个匹配项的索引:
方法1:利用IndexOf方法循环获取。
方法2:用正则来查找。
System.Text.RegularExpressions.MatchCollection matches = System.Text.RegularExpressions.Regex.Matches(input, query);
通过:matches[count].Index获取
通过:matches[count].Index获取
其中: input:表示待查找的字符串,
- query":匹配字符串,
count":第几个匹配项,从0开始。