simulate a method of consistent trim function. Remove the blank ends at both ends of the string
1. Define two variables
A variable as a corner label to judge the string space from scratch. Continuous ++
A variable as an corner label to judge the string space from the end. Continuous–
2. Determine that it is not a space, just take the string between the head and tail. (Take the skewers)
package stringd.emo;
public class stringtrim {
Public Static void main (string [] args) {
String s = "ab c";
s = mytrim (s);
System.out.println ("-"+s+"-");
}
Public Static String Mytrim (String S) {{
int Start = 0, end = s.Length ()-1;
// char, return according to the position
While (start <= end &&charat (start) == '') {
Start ++;
}
//
While (start <= end &&charat (end) == '') {
End--;
}
Return s.substring (start, end+1);
}
}