我能够将句子中的单词分开,但我不知道如何检查单词是否包含字母以外的字符。您不必发布答案,只需我可以阅读的一些材料来帮助我。
public static void main(String args [])
{
String sentance;
String word;
int index = 1;
System.out.println("Enter sentance please");
sentance = EasyIn.getString();
String[] words = sentance.split(" ");
for ( String ss : words )
{
System.out.println("Word " + index + " is " + ss);
index++;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试检查字符串是否是字母数字.我在其他帖子中尝试过很多东西,但无济于事.我尝试了StringUtils.isAlphanumeric(),一个来自Apache Commons的库,但失败了.我也从这个链接尝试了正则表达式,但这也没有奏效.有没有一种方法来检查字符串是否是字母数字并根据它返回true或false?
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = fullnameet.getText().toString();
String numRegex = ".*[0-9].*";
String alphaRegex = ".*[A-Z].*";
if (text.matches(numRegex) && text.matches(alphaRegex)) {
System.out.println("Its Alphanumeric");
}else{
System.out.println("Its NOT Alphanumeric");
}
}
});
Run Code Online (Sandbox Code Playgroud)