【发布时间】:2011-03-07 17:43:03
【问题描述】:
碰巧用户点击输入,我不想将它作为我输入的一部分包含在内,字符串可以以 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 ...)
【问题讨论】:
-
你可以在Android中使用StringUtils吗?那里有一些方便的函数来处理字符串。 commons.apache.org/lang/api/org/apache/commons/lang/…
-
我还鼓励您习惯该语言的约定 - 尽管它与问题本身无关,但您的变量通常应该使用小写驼峰式,例如
String stringWithoutBackSlashN。实际上,我发现阅读您的代码非常困难,因为您违反了命名约定。 -
andrzej,你说得对,我开始写骆驼案,但在这里看起来很丑,所以我把它改成了展示的那个