1. str.charAt(int index) 用来返回index位置下的字符,第1位是0,第2位是1,类似于数组坐标
2. 虽然java有trim方法,但是javascript没有。javascript 是直接能在网页客户端拿到数据的(如在网页上输入账号邮箱,后面有打钩校验,此过程是在客户端完成,不是在服务器端)
学习代码:public class StringTest_4 {
public static void main(String[] args) {
String s = " Lea, Happy Child Day ";
String myStr = trim(s);
System.out.println(myStr);
}
public static String trim(String s) {
int start = 0;
int end = s.length() - 1;
while (start <= end && s.charAt(start) == ' ')
start++;
while (start <= end && s.charAt(end) == ' ')
end--;
return s.substring(start, end + 1);
}
}
运行结果:
题目出自:毕向东-15-12