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

前端 未结 6 1819
闹比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:05

    This is probably the most efficient option - the item accessor is internally optimized and you can treat it as if it performs pointer arithmentic.

提交回复
热议问题