Recently, I encountered a problem of full-width half-width conversion during Chinese processing. So I searched the internet and found that the problem was basically solved, but I found that there was no space in the full-width corner, there is a bug in code for converting the half-width space into the full-width corner. The following is the modified Code: First, what is the difference between the full-width corner and the half-width corner? The width occupies two bytes, and the width occupies one byte. The halfwidth width is mainly used for punctuation. The fullwidth punctuation occupies two bytes and the halfwidth occupies one byte. The Chinese characters still occupy two bytes of Java code, regardless of the halfwidth or fullwidth. next, let's take a look at the conversion code.
Import java. Io. unsupportedencodingexception; public class fullcharconverter {public static void main (string [] ARGs) throws unsupportedencodingexception {// returns the string qjstr = "Hello !! Full-width conversion, Dao 53232 "; string result = full2halfchange (qjstr); system. out. println (qjstr); system. out. println (result); system. out. println ("----------------------------------"); // returns the string STR = "Java auto recall 2345"; system. out. println (STR); system. out. println (half2fullchange (STR);} // returns the public static final string full2halfchange (string qjstr) throws unsupportedencodingexception {stringbuffer outstrb UF = new stringbuffer (""); string tstr = ""; byte [] B = NULL; For (INT I = 0; I <qjstr. length (); I ++) {tstr = qjstr. substring (I, I + 1); // convert all-width spaces to half-width spaces if (tstr. equals ("") {outstrbuf. append (""); continue;} B = tstr. getbytes ("Unicode"); // get the Unicode byte data if (B [2] =-1) {// indicates the full angle? B [3] = (byte) (B [3] + 32); B [2] = 0; outstrbuf. append (new string (B, "Unicode");} else {outstrbuf. append (tstr) ;}// end. return outstrbuf. tostring () ;}// returns the fullwidth public static final string half2fullchange (string qjstr) throws unsupportedencodingexception {stringbuffer outstrbuf = new stringbuffer (""); string tstr = ""; byte [] B = NULL; For (INT I = 0; I <qjstr. length (); I ++) {tstr = qjstr. substring (I, I + 1); If (tstr. equals ("") {// halfwidth space outstrbuf. append (tstr); continue;} B = tstr. getbytes ("Unicode"); If (B [2] = 0) {// halfwidth? B [3] = (byte) (B [3]-32); B [2] =-1; outstrbuf. append (new string (B, "Unicode");} else {outstrbuf. append (tstr) ;}} return outstrbuf. tostring ();}}