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 no开发者_如何学Got 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;
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论