Detect if a string contains uppercase characters

前端 未结 7 913
孤城傲影
孤城傲影 2021-01-17 09:32

Is there an alternative to using a regular expression to detect if a string contains uppercase characters? Currently I\'m using the following regular expression:

<         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 09:49

    Using LINQ might have an impact on performance when using a large string . You can also use ASCII level comparison.

    byte[] asciiBytes = Encoding.ASCII.GetBytes(fullUri);
    for (int i = 0; i < asciiBytes.Length; i++)
    {
        if (asciiBytes[i] > 64 && asciiBytes[i] < 91)
        {
            return true;
        }
    }
    

提交回复
热议问题