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?
Since the string S2 occurs twice as a non-overlapping subsequence in S1, the required output is 2.
Regex.Matches(input, "OU=").Count
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With