开发者

how to find String contain any alphabetic or numeric characters using java? [duplicate]

This question already has answers here: 开发者_Python百科 Closed 11 years ago.

Possible Duplicate:

Simple way to determine if string is only characters, or to check if string contains any numbers in Java

I want to find if a given String has any alphabetic or numeric characters. How would I do this using java?

Thanks


String s = "%$a*";
Pattern p = Pattern.compile("[a-zA-Z0-9]");
Matcher m = p.matcher(s);
if (m.find())
  System.out.println("The string \"" + s + "\" contains alphanumerical characters.");


Take a look at this: http://www.regular-expressions.info/java.html


There are two convenience methods in the Character class that would help you

  • isLetter(...)
  • isDigit(...)

All that's required is transforming a String to a character array, and then stepping through the array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜