您可以使用Path.GetFileName方法来获取字符串中不带路径的文件名。

以下是一个示例代码:

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string filePath = @"C:\Users\Username\Documents\file.txt";

        string fileName = Path.GetFileName(filePath);

        Console.WriteLine(fileName);
    }
}

输出结果为:file.txt

C# 获取字符串中不带路径的文件名

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

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