36
4

2 回答 2

46

ASCII 范围为 0 - 127,因此只需检查该范围:

char c = 'a';//or whatever char you have
bool isAscii = c < 128;
于 2013-09-03T15:40:37.577 回答
33
bool HasNonASCIIChars(string str)
{
    return (System.Text.Encoding.UTF8.GetByteCount(str) != str.Length);
}
于 2019-10-09T13:23:20.427 回答