如何检查点之前和之后是否有空格?
示例输出:
ABCSF.GHJJKA = true;
ABCSF . GHJJKA = false;
ABCSF. GHJJKA = false;
ABCSF .GHJJKA = false;
ABCSFGHJJKA = false;
ABCSF GHJJKA = false;
我使用example.matches();
编辑:
AB CSF.GHJ JKA = true;
AB CSF.GHJJKA = true;
ABCSF.GHJ JKA = true;
答案 0 :(得分:1)
使用以下正则表达式符合您的要求
[\w]+\.[\w]+
答案 1 :(得分:0)
这是帮助您确定空格中的空格的代码 串。
<强> WhiteSpace.java 强>
public class WhiteSpace {
public static void main(String[] args) {
String test_str = "My.name.is.anthony"; //Declare and define a string
boolean flag = false ; // Initialize boolean variable flag to false
//For loop that iterates through the entire string
for(int i = 0 ; i < test_str.length() ; i++ ){
if(Character.isWhitespace(test_str.charAt(i))){ //check whether the current character is a white space
flag = true;
break; //Breaks as soon as the first white space is encountered
}
}
if(flag == true ){
System.out.println("The string has a white space!!");
}else{
System.out.println("No white space!!");
}
}
}