public class StringDemo6 {
public static void main(String[] args) {
String s1=" a g t ";
System.out.println(s1.trim());//其实一句话就实现了,重点在于思路
//System.out.println(s1);
String s=" a g t ";
s=MyTrimArry(s);
System.out.println(s);
}
public static String MyTrimArry(String s) {
int first=0;
int end=s.length()-1;
while(first<=end && s.charAt(first)==' '){
first++;
}
while(first<=end&&s.charAt(end)==' '){
end--;
}
return s.substring(first, end+1);
}
}
{:2_30:} |
|