文章詳情頁
Java Regex刪除新行,但保留空格。
瀏覽:82日期:2024-05-03 14:24:37
如何解決Java Regex刪除新行,但保留空格。?
您不必使用正則表達式;您可以使用trim()和replaceAll()代替。
String str = ' n a b c n 1 2 3 n x y z '; str = str.trim().replaceAll('n ', '');
這將為您提供您要查找的字符串。
解決方法對于字符串,' n a b c n 1 2 3 n x y z '我需要它成為'a b c 1 2 3 x y z'。
使用此正則表達式str.replaceAll(“( s | n)”,“”); 我可以得到“ abc123xyz”,但是如何在兩者之間獲得空格。
標簽:
java
排行榜
