Java 如何在字符串中用单个空格替换 2 个或更多空格,并删除前导空格和尾随空格
在Java中寻找快速,简单的方法来更改此字符串
" hello there "
到看起来像这样的东西
"hello there"
其中,我将所有这些多个空格替换为单个空格,除了我还希望字符串开头的一个或多个空格消失。
像这样的东西让我部分地在那里
String mytext = " hello there ";
mytext = mytext.replaceAll("( )+", " ");
但不完全是。