In C#, how can I detect if a character is a non-AS

2020-06-07 07:54发布

I would like to check, in C#, if a char contains a non-ASCII character. What is the best way to check for special characters such as or Ω?

2条回答
啃猪蹄的小仙女
2楼-- · 2020-06-07 08:32

ASCII ranges from 0 - 127, so just check for that range:

char c = 'a';//or whatever char you have
bool isAscii = c < 128;
查看更多
beautiful°
3楼-- · 2020-06-07 08:44
bool HasNonASCIIChars(string str)
{
    return (System.Text.Encoding.UTF8.GetByteCount(str) != str.Length);
}
查看更多
登录 后发表回答