The main difference here is that the character decoding of the full-width string getbytes () is different from the getbytes () bytecode of the half-width string.
The half-width bytecode is 32, and the full-width bytecode is-95-95. We only need to replace it with 32 here.
Here I provide a class method that can replace the full-width null bytecode with the 32-byte bytecode. Very useful.
Public class removespaces {
Public static final string removespace (string SS ){
Byte [] T = ss. getbytes ();
For (INT I = 0; I <t. length; I ++ ){
If (T [I] =-95 & T [I + 1] =-95 ){
T [I] = 32;
If (I + 1 = T. Length-1 ){
T [I + 1] = 0;
} Else {
For (Int J = I + 1; j + 1 <t. length; j ++ ){
T [J] = T [J + 1];
If (J + 1 = T. Length-1) T [J + 1] = 32;
}
}
}
}
Return new string (t );
}
Public static void main (string Arg []) {
String test = "I am a good man ";
String result = removespace (test );
System. Out. println (test + "/N" + result );
}
}