I tried to type char literals for accentuated vowels in Java, but the compilers says something like: unclosed character literal
This is what I’m trying to do:
char [] a = {'à', 'á', 'â', 'ä' };
I’ve tried using Unicode '\u00E0' but for some reason they don’t match with my code:
for( char c : string.toCharArray() ) {
if( c == a[i] ) {
// I've found a funny letter
}
}
The if never evaluates to true, no matter what I put in my string.
Here’s the complete program I’m trying to code.
The code should be compiled with the correct encoding:
There’ll be an encoding mismatch there somewhere.
The above code saved as UTF-8 should become the hex dump:
The UTF-8 value for code point U+00E0 (à) is
C3 A0.The code should be compiled with the correct encoding:
There is an outside chance that à will be represented by the combining sequence U+0061 U+0300. This is the NFD form (I’ve never come across a text editor that used it as a default for text entry). As Thorbjørn Ravn Andersen points out, it is often better to always use \uXXXX escape sequences – it is less ambiguous.
You also need to check your input device (file/console/etc.)
As a last resort, you can dump your
chars as hexSystem.out.format("%04x", (int) c);and try manually decoding them with a character inspector to find out what they are.