I have some string with text, I want to count all occurrences of Environment.NewLine
.
I thought to something in a way like
MyString.Where(c => c == Environment.NewLine).Count();
But c
is only one char so it will not work .
Any better suggestions ?
With Regex:
int count = Regex.Matches(input, Environment.NewLine).Count;
With String.Split:
int count = input.Split(new string[] { Environment.NewLine },
StringSplitOptions.None).Length - 1;
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