我有一个需要解析的大字符串,我需要查找所有实例extract"(me,i-have lots. of]punctuation,并将每个的索引存储到列表中.
所以说这条字符串位于较大字符串的开头和中间,它们都会被找到,并且它们的索引会被添加到字符串中List.而List将包含0与其他指数不管它是.
我一直在玩弄和string.IndexOf做几乎就是我正在寻找的,我已经写了一些代码-但它不工作,我一直无法弄清楚到底什么是错的:
List<int> inst = new List<int>();
int index = 0;
while (index < source.LastIndexOf("extract\"(me,i-have lots. of]punctuation", 0) + 39)
{
int src = source.IndexOf("extract\"(me,i-have lots. of]punctuation", index);
inst.Add(src);
index = src + 40;
}
Run Code Online (Sandbox Code Playgroud)
inst =清单source =大字符串有更好的想法吗?
如何使用c#查找字符串中模式的所有索引?
例如,我想##在这样的字符串中找到所有模式索引45##78$$#56$$JK01UU
嗨,我正在尝试使用解决方案
但是,它在我的情况下不起作用
string sentence = "A || ((B && C) || E && F ) && D || G";
string pattern = "(";
IList<int> indeces = new List<int>();
foreach (Match match in Regex.Matches(sentence, pattern))
{
indeces.Add(match.Index);
}
Run Code Online (Sandbox Code Playgroud)
它产生错误,"解析"(" - 不够)".
我不确定我在这里做错了什么.
感谢任何帮助.
谢谢,
Balan Sinniah