How to count of sub-string occurrences within a string (not char occurrences)
c#, string
Solution
Regex.Matches(input, "OU=").Count
Problem
Suppose I have a string like: ``` MyString = "OU=Level3,OU=Level2,OU=Level1,DC=domain,DC=com"; ``` then I want to know how many time of occurrences of sub-string "OU=" in this string. With single char, maybe there is something like: ``` int count = MyString.Split("OU=").Length - 1; ``` but `Split` only works for `char`, not `string`. Also how to find the position of n occurrences? For example, the position of 2nd `"OU="` in the string? How to resolve this issue?