string input = "Hello World!";
if (!string.IsNullOrEmpty(input))
{
// 使用 Substring 方法去掉最后一个字符
string result = input.Substring(0, input.Length - 1);
Console.WriteLine(result); // 输出: Hello World
}
else
{
Console.WriteLine("输入字符串为空或null");
}
string.IsNullOrEmpty(input) 来确保输入的字符串不是空或 null,避免在处理时出现异常。Substring 方法从索引 0 开始提取字符串,长度为 input.Length - 1,即去掉最后一个字符。上一篇:c#排序
下一篇:c# findwindow
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站