Possible Duplicate:
How would you count occurences of a string within a string (C#)?
I have a string that has multiple sub-strings and Enter (special character by pressing Enter key) between them.
Can you please guide me how to write a regular expression that counts Enter keys between words ?
Thanks
You don't need a regex, you're just counting strings. Specifically you're just counting Environment.Newline
s. There's lots of ways to do that; several are described in this SO answer. Here's one which looks inefficient but performs surprisingly well:
int count1 = source.Length - source.Replace(Environment.Newline, "").Length;
Depending on the line break symbol used you may have to change to just \r
or just \n
.
var numberLineBreaks = Regex.Matches(input, @"\r\n").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