• C# 获取路径中文件名、目录、扩展名等


    string path = "C:\dir1\dir2\foo.txt";  

    string str = "GetFullPath:" + Path.GetFullPath(path) + " ";
    str += "GetDirectoryName:" + Path.GetDirectoryName(path) + " ";
    str += "GetFileName:" + Path.GetFileName(path) + " ";
    str += "GetFileNameWithoutExtension:" + Path.GetFileNameWithoutExtension(path) + " ";
    str += "GetExtension:" + Path.GetExtension(path) + " ";
    str += "GetPathRoot:" + Path.GetPathRoot(path) + " ";

    MessageBox.Show(str);
    结果:
    GetFullPath:C:dir1dir2foo.txt
    GetDirectoryName:C:dir1dir2
    GetFileName:foo.txt
    GetFileNameWithoutExtension:foo
    GetExtension:.txt
    GetPathRoot:C:
  • 相关阅读:
    指针、字符串、数组操作
    字符串转换为数字(str2int)
    新的,开始。
    Hello, World.
    Go语言趣学指南lesson1
    hdoj2058
    poj2378
    hdoj1233
    poj2398
    hdoj1392
  • 原文地址:https://www.cnblogs.com/vip-ygh/p/3620808.html
Copyright © 2020-2023  润新知