ASCII defines only character codes in the range 0-127 . Unicode explicitly defined as overlapping in the same range with ASCII. Thus, if you look at the character codes in your string and contains everything above 127, the string contains Unicode characters that are not ASCII characters.
Please note that ASCII only includes the English alphabet. Thus, if you (for some reason) need to apply the same approach to strings that may contain accented characters (for example, in Spanish text), ASCII is not enough, and you need to look for another differentiator.
ANSI character set [*] extends ASCII characters with the aforementioned Latin letters in the range 128-255 . However, Unicode does not overlap with ANSI in this range, so technically the Unicode string can contain characters that are not part of ANSI but have the same character code (in particular, in the range 128-159 , as you can see from the table I'm associated with).
Regarding the actual code for this, the answer to @chibacity should work, although you have to change it to cover strict ASCII, because it will not work for ANSI.
[*] Also known as Latin 1 Windows (Win-1252)
Franci Penov Dec 16 '10 at 10:58
source share