Public String trim () {
int len = value.length;
int st = 0;
Char[] val = value; /* Avoid GetField opcode
/while ((St < Len) && (val[st] <= ')) {
st++;
}
while ((St < Len) && (val[len-1] <= ')) {
len--
}
Return (St > 0) | | (Len < value.length)) ? SUBSTRING (ST, Len): this;
}
St=0, start the loop from the left of the array, and when you encounter the first character that is not empty, jump out of the loop
Then start the loop from the right of the array, and jump out of the loop when you encounter the first character that is not empty.
Finally, the array is returned.
String str1 = " 333";
String str2 = "All ";
String STR3 = " 444 ";
String STR4 = "555 666";
System. out. println (Str1.trim ());
System. out. println (Str2.trim () + "removed");
System. out. println ("removed" +str3.trim () + "removed");
System. out. println (Str4.trim ());
Output: 333
Did 22 get rid of it?
Did you get rid of the 444?
555 666
Trim () will remove the space between the left and right sides, the middle of the space can not be removed.