If you figure out the relationship between Full-width and half-width characters in Java
Then the transition between them is not a thing at all.
You can use the following procedure to look at all the characters in Java and the corresponding encoded values
public static void Main (string[] args) {
for (int i = Character.min_value i <= character.max_value; ++i) {
SYSTEM.OUT.PRINTLN (i + "" "+ (char) i);
}
}
From the output you can see
1, half-width characters are starting from 33 to 126 end
2, the full-width character corresponding to the half-width character is from 65281 start to 65374 end
3, the half corner of the space is 32. The corresponding Full-width space is 12288
The relationship between Half-width and Full-width is obvious, except that the character offset is 65248 (65281-33 = 65248).
The Java language realizes the conversion between Full-width and Half-width
Understand the relationship between Full-width characters, and then look at the implementation of Java
/**
* Full-angle string conversion half-corner string
*
* @param fullwidthstr
* Non-empty full-width string
* @return Half-angle string
*/
private static string Fullwidth2halfwidth (String fullwidthstr) {
if (null = = Fullwidthstr | | fullwidthstr.length () <= 0) {
Return "";
}
char[] Chararray = Fullwidthstr.tochararray ();
Char array traversal of full-width character conversions
for (int i = 0; i < chararray.length; ++i) {
int charintvalue = (int) chararray[i];
If the conversion relationship is satisfied, the offset between the corresponding subscript is reduced by 65248; if it's a space, just do the conversion.
if (charintvalue >= 65281 && charintvalue <= 65374) {
Chararray[i] = (char) (charIntValue-65248);
else if (Charintvalue = 12288) {
Chararray[i] = (char) 32;
}
}
return new String (Chararray);
}