I have a line with text, I want to count all occurrences of Environment.NewLine .
Environment.NewLine
I thought of something like
MyString.Where(c => c == Environment.NewLine).Count();
But c is only one char, so it will not work.
c
Any best deals?
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;
Source: https://habr.com/ru/post/891878/More articles:Should I learn C # or Java? - javaImplementing a probability distribution function in Java - javaMongoDB query to retrieve a single array value by the value in the array - arraysPropertyInfo.GetSetMethod (true) does not return a method for properties from the base class - reflectionwhy initialize this byte array to 1024 - javaCompressing images with a copy of Rails compared to what the Speed page produces - ruby-on-railshttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/891880/can-aspectj-add-methods-to-javalangstring&usg=ALkJrhjm2com-bGd-gRwsY2XkQabEXZrlgHow to get a specific icon in a container (e.g. dll) in XAML? - wpfWiener Filtering - filterHow to check if a file is plain text? - javaAll Articles