![](/img/trans.png)
[英]I want to check the whitespace of a string and want to print the first character just after the whitespace to a upper case letter
[英]How can I check for no whitespace before and after a character?
如何檢查點前后是否沒有空格?
示例輸出:
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;
使用下面的正則表達式來滿足您的要求
[\w]+\.[\w]+
以下代碼將幫助您確定字符串中的空格。
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!!");
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.