要去除字符串的最后一个字符,可以使用Substring方法来实现。以下是一个示例代码:
string str = "Hello World";
string newStr = str.Substring(0, str.Length - 1);
Console.WriteLine(newStr); // 输出 "Hello Worl"
在上面的代码中,我们通过调用Substring方法来截取字符串的子串,从索引0开始到字符串的倒数第二个字符为止。这样就实现了去除字符串的最后一个字符的效果。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php如何去除最后一个字符