在Java中寻找快速,简单的方法来更改此字符串
" hello there "
Run Code Online (Sandbox Code Playgroud)
看起来像这样的东西
"hello there"
Run Code Online (Sandbox Code Playgroud)
我用一个空格替换所有这些多个空格,除了我还希望字符串开头的一个或多个空格不见了.
像这样的东西让我部分在那里
String mytext = " hello there ";
mytext = mytext.replaceAll("( )+", " ");
Run Code Online (Sandbox Code Playgroud)
但不完全.