2011-09-02 48 views

回答

4

假設你的意思是「連續」空格,這裏有一個解決方案。

String sentence = "hello here are \n some whitespaces."; 
String newString = sentence.replaceAll("\\s+", " "); 
System.out.println(newString); 

輸出:

hello here are some whitespaces. 
+0

這裏的句子是什麼 – gauravgarg9191

+0

中間有空格的單詞串。 – aioobe

相關問題