Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c#去掉最后一个字符

作者:淡情   发布日期:2025-11-24   浏览:50

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");
}

解释说明:

  1. 检查字符串是否为空或null:使用 string.IsNullOrEmpty(input) 来确保输入的字符串不是空或 null,避免在处理时出现异常。
  2. 去掉最后一个字符:使用 Substring 方法从索引 0 开始提取字符串,长度为 input.Length - 1,即去掉最后一个字符。
  3. 输出结果:将处理后的字符串输出到控制台。

上一篇:c#排序

下一篇:c# findwindow

大家都在看

c# 二进制

c# datatable group by

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#获取系统时间

c#游戏开发

c#网络编程

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站