У меня есть большая строка, которую мне нужно проанализировать, и мне нужно найти все экземпляры 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
= Большая строка
Любые лучшие идеи?