java 如何使用java查找包含任何字母或数字字符的字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6596078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to find String contain any alphabetic or numeric characters using java?
提问by Sameek Mishra
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?
我想查找给定的字符串是否有任何字母或数字字符。我将如何使用 java 做到这一点?
Thanks
谢谢
回答by SteeveDroz
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.");
回答by mre
There are two convenience methods in the Character
class that would help you
Character
课程中有两个方便的方法可以帮助您
All that's required is transforming a String
to a character array, and then stepping through the array.
所需要做的就是将 aString
转换为字符数组,然后逐步遍历该数组。
回答by Ovais Khatri
Take a look at this: http://www.regular-expressions.info/java.html