So I've been working on a little something to help me with some maths and display working and all is working well, yet for the console output I need to be able to display Unicode superscript and subscript. I had it set up initially with the following function for superscript:
public static String getBase( int num ){
String uniStr = "\\u207";
String numStr = Integer.toString(num);
String res = "";
for( int i = 0; i < numStr.length(); i++ ){
String s = uniStr + numStr.charAt(i);
char c = (char) Integer.parseInt( s.substring(2), 16 );
res += c;
}
return res;
}
That worked fine to an extent, but when using the following call to debug:
System.out.println(Unicode.getBase(1234567890));
I got the output:
ⁱ⁴⁵⁶⁷⁸⁹⁰
due to the superscript for 1, 2 and 3 having far different unicode IDs in the Latin1-Supplement unicode block, as opposed to being in the superscript/subscript block with the other characters. So I added a switch statement in an attempt to handle these 3 specifically, resulting in:
public static String getBase( int num ){
String uniStr = "\\u207";
String numStr = Integer.toString(num);
String res = "";
for( int i = 0; i < numStr.length(); i++ ){
String s = "";
switch(numStr.charAt(i))
{
case '1':
s = "\\u00B9";
break;
case '2':
s = "\\u00B2";
break;
case '3':
s = "\\u00B3";
break;
default:
s = uniStr + numStr.charAt(i);
}
char c = (char) Integer.parseInt( s.substring(2), 16 );
res += c;
}
return res;
}
And yet now I get the output:
¹²³⁴⁵⁶⁷⁸⁹⁰
except for the fact that only 1, 2 and 3 now display in the console, with 4-0 all having the invalid character box like:
¹²³ࢆࢆࢆࢆࢆࢆࢆ
I know for a fact that the switch works, as proven by 1, 2 and 3 all showing correctly, and the parsing of the string for the other characters works also, yet this still happens. For the life of me I cannot find a solution or even a reason to this. If I use characters from one Unicode block is it trying to grab all further characters from that range also, and if so is there anything I can do about it? That seems the only likely cause I can think of, otherwise I'm well and truly stumped. Any and all help would be hugely appreciated.
P.S. I have my run configs in Eclipse set to UTF-8 and all these characters are supported