碰巧用户单击 Enter,而我不想将其作为输入的一部分,该字符串可以以 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.
或者至少现在将值转储到GC......
所以两个q:
- 有更有效的方法吗?..
- 我该称呼谁为编译器(android 上的 java ...)
最佳答案
此方法删除字符串末尾的所有字符,这些字符的 ascii 代码小于空格(间隔,32)。这包括 \n
(10)。
关于java - 字符串以 '\n' 结尾最有效的操作方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3108897/