在 C# 中,可以使用以下代码来移除字符串末尾的路径分割符:

string path = 'C:\folder\subfolder\';
if (path.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
    path = path.Remove(path.Length - 1);
}

这段代码首先检查字符串 'path' 是否以路径分割符结尾,如果是,则使用 'Remove' 方法移除末尾的字符。'Path.DirectorySeparatorChar' 是一个常量,表示当前操作系统的路径分割符。

C# 移除字符串末尾的路径分割符

原文地址: https://www.cveoy.top/t/topic/oP1O 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录