Question: How can I find all indexes of a pattern in a string using c#? 

For example I want to find all `##` pattern indexes in a string like this `45##78$$#56$$JK01UU`

Answer: 
```
 string pattern = "##";
 string sentence = "45##78$$#56$$J##K01UU";
 IList<int> indeces = new List<int>();
 foreach (Match match in Regex.Matches(sentence, pattern))
 {
      indeces.Add(match.Index);
 }

```

indeces will have 2, 14
Another one that tries to be efficient:

```
public IEnumerable<int> FindPatternIndexes(string input, string search)
{
    var sb = new StringBuilder(input);

    for (var i = 0; search.Length <= sb.Length; i++)
    {
        if (sb.ToString().StartsWith(search)) yield return i;
        sb.Remove(0,1);
    }
}

```