What is the fastest way to count newlines in a large .NET string?

前端 未结 6 1827
闹比i
闹比i 2021-02-13 04:18

Is there a way to improve this:

private static int CountNewlines(string s)
{
    int len = s.Length;
    int c = 0;
    for (int i=0; i < len;  i++)
    {
           


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-13 05:12

    Make it an instance method, if you'll use it in a loop.

提交回复
热议问题