public static IndexesOf ( this haystack, string needle ) : IEnumerable |
||
haystack | this | |
needle | string | |
return | IEnumerable |
public static IEnumerable<int> IndexesOf(this string haystack, string needle)
{
int lastIndex = 0;
while (true) {
int index = haystack.IndexOf(needle, lastIndex);
if (index == -1) {
yield break;
}
yield return index;
lastIndex = index + needle.Length;
}
}