例如,如果您有一个制表符分隔值列表:
foo1\tfoo2\tfoo3\tfoo4\t
最后一个\t是由于自动将\t附加到每个+=
.
你如何以简单的方式删除最后一个\t ?所以结果是:
foo1\tfoo2\tfoo3\tfoo4
作为 Hover 的请求,我有一个小例子:
String foo = "";
for (int i = 1; i <= 100; i++) {
foo += "foo" + "\t";
if (i % 10 == 0) {
foo = foo.trim(); // wasn't working
foo += "\n";
}
}
System.out.println(foo);
输出(用字符串选项卡替换实际选项卡以在此处显示):
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
foo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\tfoo\t
这就是我问这个问题的主要原因, .trim() 不起作用,因此,我坚持认为 trim() 不是为尾随制表符制作的。