我想知道下面的代码有什么问题。
public void onClickSave (View cs)
{
Pattern pattern = Pattern.compile("@");
Matcher matcher = pattern.matcher(userid);
boolean found = matcher.find();
if(found){
//do stuff
所以目标是检查字符串中是否有 @ 符号。不知道我错过了什么新的 Java。感谢您的帮助
最佳答案
为什么你不尝试使用 contains 方法?
String userID = "@Test";
boolean found = userID.contains("@");
但这也对我有用:
String userID = "@Test";
Pattern pattern = Pattern.compile(".*@.*");
Matcher matcher = pattern.matcher(userID);
boolean found = matcher.find();
关于java - 如何验证 "@"符号的字符串并传递给 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11587195/