如何使用 C# 查找字符串中某个模式的所有索引?
例如,我想在这样的字符串中找到所有 ##
模式索引 45##78$$#56$$JK01UU
最佳答案
string pattern = "##";
string sentence = "45##78$$#56$$J##K01UU";
IList<int> indeces = new List<int>();
foreach (Match match in Regex.Matches(sentence, pattern))
{
indeces.Add(match.Index);
}
指数将有 2, 14
关于c# - 在 C# 中查找字符串中的所有模式索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10546302/