我有一个很大的字符串需要解析,我需要找到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;
}
inst
= The listsource
= The large string有更好的主意吗?
https://stackoverflow.com/questions/2641326
复制相似问题