Problem with Character.getNumericValue

String name = "bobboli -_()あ!.。県きkk";

(inside a for loop)

int codePoint = name.codePointAt(i);

System.out.print(name.codePointAt(i) + " " + name.charAt(i));

Returns: A bunch of code point numbers and the characters of what cmd.exe can display (cmd doesn't display unicode, but that is another issue)

char bill = 'あ';

System.out.println(" " + Character.getNumericValue(bill));

System.out.println(" " + Character.getNumericValue('a'));

System.out.println(" " + Character.getNumericValue('.'));

Returns:

-1

10

-1

Where from the first bit of code, I know that あ (japanese 'a') is 12354, but I don't understand why I am getting -1 when trying to get the NumericValue as well as -1 for '.'

Encoding is utf-8 for the file, and I run javac -encoding utf-8 on the java file

[920 byte] By [JeuLaFetea] at [2007-11-27 9:56:17]
# 1
You need to read getNumericValue's docs more closely. It doesn't do what you think it does.
jverda at 2007-7-13 0:26:24 > top of Java-index,Java Essentials,New To Java...
# 2
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Character.html#getNumericValue(char)
Navy_Codera at 2007-7-13 0:26:24 > top of Java-index,Java Essentials,New To Java...
# 3
Please read the method's documentation:"If the character does not have a numeric value, then -1 is returned."What are you trying to do? This is probably not the correct solution.
ChuckBinga at 2007-7-13 0:26:24 > top of Java-index,Java Essentials,New To Java...
# 4

(int)' <japanese a goes here> '

gives 12354.

I'm too braindead right now to think about whether you'd need to worry about casting to long and masking or something to ensure you always get a positive number. I think casting to int is fine, but play around with it.

EDIT: Stupid forum doesn't like *my* 'a' for some reason.

jverda at 2007-7-13 0:26:24 > top of Java-index,Java Essentials,New To Java...
# 5
Well, gee, amazing what happens when one actually reads the docs. Yea, I was using it, in vain, to get a char->codepoint conversion and didn't bother to find out it does. Thanks for the tip jverd.Message was edited by: JeuLaFete
JeuLaFetea at 2007-7-13 0:26:24 > top of Java-index,Java Essentials,New To Java...
# 6
You're welcome. Glad to be able to help.
jverda at 2007-7-13 0:26:24 > top of Java-index,Java Essentials,New To Java...