【发布时间】:2010-04-14 21:52:47
【问题描述】:
我有一个大字符串需要解析,我需要找到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= 列表 -
source= 大字符串
有更好的想法吗?
【问题讨论】: