我有一个很大的字符串需要解析,我需要找到extract"(me,i-have lots. of]punctuation
的所有实例,并将每个实例的索引存储到一个列表中.
假设这段字符串位于较大字符串的开头和中间,它们都将被找到,它们的索引将被添加到List
.List
将包含0
和其他索引,不管它是什么.
我一直在玩,string.IndexOf
做了我想要的almost,我写了一些代码-但它不起作用,我也不能准确地找出哪里出了问题:
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
=列表 -
source
=大字符串
还有更好的主意吗?