日期:2014-05-20  浏览次数:20624 次

求Java.land包中的String类中的方法
String类中有没有一个判断指定的字符串是否是Java中合法的标识符的方法?
小弟目前解决的方法是将字符串中的字符逐个取出用isJavaidentifirestart()和isJavaidentifirepast()方法进行判断,但是觉得这个方法太麻烦,有没有直接判断字符串的方法

------解决方案--------------------
不要想了,没有这样的方法
------解决方案--------------------
the key is no
------解决方案--------------------
JAVA没想得这么周全~~可以用
boolean contains(CharSequence s)
当且仅当此字符串包含 char 值的指定序列时,才返回 true。
来判断是否包含非法字符 比一个个拿出来再判断好
------解决方案--------------------
自己写个方法不就完了
------解决方案--------------------
String a = "随便什么 ";

System.out.println(a.matches(正则表达式));

需要判断什么字符就写个正则不就行了
------解决方案--------------------
if (obj instanceof String) { // 字符串
else if (obj instanceof Integer || obj instanceof Float
|| obj instanceof Double || obj instanceof Short
|| obj instanceof Byte || obj instanceof Long) { // 数值
} else if (obj instanceof Date) { // 日期
} else {throw new SQLException( "An unkown type of field value is encountered. ");
}

instanceof可以判断是什么类型