C# 只移除最后一个字符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 只移除最后一个字符相关的知识,希望对你有一定的参考价值。

string str = "|||";
Console.WriteLine(str.Substring(0, str.Length - 1));
Console.WriteLine(str.Remove(str.LastIndexOf("|"), 1));
Console.WriteLine(str.Remove(str.Length - 1));
注:用str.TrimEnd(‘|‘)会将所有的|都会清除!

推荐使用  Substring;

以上是关于C# 只移除最后一个字符的主要内容,如果未能解决你的问题,请参考以下文章