I have this:
string strings = "a b c d d e";
And I need something similar to string.Contains()
, but I need to know not only whether a string is present(in case above a letter), but also if it is present only ONE SINGLE time.
How can I achieve this?
You can use LastIndexOf(String)
and IndexOf(String)
and verify that the values returned are equal. Of course also check if the String is found at all(i.e the returned value is not -1).
You could use LINQ
int count = strings.Count(f => f == 'd');
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