在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)
但不完全.
我正在尝试制作一个简单的正则表达式来检查一行是否为空.
案件;
" some" // not blank
" " //blank
"" // blank
Run Code Online (Sandbox Code Playgroud) 我有这样的字符串
"hello
java
book"
Run Code Online (Sandbox Code Playgroud)
我想从字符串中删除\ r和\n(hello\r \n \njava\r \nbook).我想要一个字符串作为"hellojavabook".我怎样才能做到这一点?
碰巧用户点击输入我不希望将其包含在我输入的一部分中,字符串可以以3次结束\n所以只需替换一个不会完成我的解决方案的工作;
String values[] = string_Ends_With_Back_Slash_N.split("\n");
String String_without_Back_Slash_N =new String (values [0]);
//or just to point there without the new but i want later to dump the garbage.
Run Code Online (Sandbox Code Playgroud)
或者至少现在将值转储到gc ....
所以两个q: