这里的问题非常简单(更多的是为了确认我的想法,而不是任何事情)......
Java方法:StringBuffer.Delete(start,end) ;
Java代码:
sb.delete(sb.length()-2, sb.length());
C#(不确定这是否正确):
StringBuilder sb = new StringBuilder();
....
sb.Remove(sb.Length - 2, sb.Length - (sb.Length - 2));
我不确定的原因是在Java删除方法的文档中。它说
The substring begins at the specified start and extends to the character at index end - 1 or to the end of the StringBuffer if no such character exists
我只是不太确定这句话的end - 1部分..以及我是否可能把事情搞砸了。
干杯:)
编辑:呵呵。我知道它正在从字符串中删除最后 2 个字符,但我保持了转换的精确性,因此我的代码很冗长。 :)
最佳答案
要删除您写入的最后 2 个字符:
sb.Remove(sb.Length - 2, 2);
关于c# - 这个基本 Java 方法的等效 C# 方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/574171/