缘起
第一次了解他是在一次上课,老师提起一位学长参加面试时,被问到是否了解正则表达式。遂开始找相关书,学习了一段时间,现在为止,勉强能用,学习速度还是有点慢。
java中判断字符串是否为数字的三种方法
public static boolean isNumeric(String str){
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
2用正则表达式
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
3用ascii码
public static boolean isNumeric(String str){
for(int i=str.length();--i>=0;){
int chr=str.charAt(i);
if(chr<48 || chr>57)
return false;
}
return true;
}
给出几个可以学习的网站(按喜欢的顺序)
1.http://deerchao.net/tutorials/regex/regex.htm
2.http://baike.xsoftlab.net/view/207.html
3.http://www.cnblogs.com/elleniou/archive/2012/07/31/2617312.html
4.http://www.runoob.com/regexp/regexp-syntax.html
5.http://lavasoft.blog.51cto.com/62575/179324/