Skip to content

Instantly share code, notes, and snippets.

@NiKoTron
Last active August 4, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NiKoTron/eca8c7449fbcfdefb324e85a34404532 to your computer and use it in GitHub Desktop.
Save NiKoTron/eca8c7449fbcfdefb324e85a34404532 to your computer and use it in GitHub Desktop.
get all entries in string
public static List<int> AllIndexesOf (this string str, string value)
{
if (System.String.IsNullOrEmpty (value))
throw new ArgumentException ("строка не может быть пустой", "value");
List<int> indexes = new List<int> ();
for (int index = 0;; index += value.Length) {
index = str.IndexOf (value, index);
if (index == -1)
return indexes;
indexes.Add (index);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment