The problem with converting characters to euros

I am trying to put the euro symbol in a Java string, which is passed to a native function (using JNA) as follows:

/*JAVA*/
String s= new String("Euro symbol=€");

nativefunction(s.getBytes(US-ASCII));


/*C++*/
void nativefunction(char *s)
{
    printf("%s",s);
}

native function output: Euro symbol=?

Why the character is printed as ?instead of .

I also tried using the ascii code of the euro symbol ( \0x80), but the result is the same.

Can someone stop me?

Thanks in advance,

Kevin

+3
source share
2 answers

US-ASCII does not contain the euro symbol. Perhaps you meant Windows-1252, if so, use:

nativefunction(s.getBytes("Windows-1252")); 

If it still doesn't work, try using the Unicode escape sequence in Java code:

String s= new String("Euro symbol=\u20ac");  

\u20ac, , .

+4

, Java UTF-16, cahracter. UTF - U + 20AC, 0x20AC UTF-16. US-ASCII . ascii, . CharSetEncoder.

0

All Articles