C++ Extended Ascii characters

2019-05-29 10:58发布

How to detect the presence of Extended ASCII values (128 to 255) in a C++ character array.

8条回答
何必那么认真
2楼-- · 2019-05-29 11:41

Please remember that there is no such thing as extended ASCII. ASCII was and is only defined between 0 and 127. Everything above that is either invalid or needs to be in a defined encoding other than ASCII (for example ISO-8859-1).

Please read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).

Other than that: what's wrong with iterating over it and check for any value > 127 (or <0 when using signed chars)?

查看更多
Juvenile、少年°
3楼-- · 2019-05-29 11:41

Char can be signed or unsigned. This doesn't really matter, though. You actually want to check if each character is valid ASCII. This is a positive, non-ambiguous check. You simply check if each char is both >=0 and <= 127. Anything else (whether positive or negative, "Extended ASCII" or UTF-8) is invalid.

查看更多
登录 后发表回答