c#根据绝对路径获取 带后缀文件名、后缀名、文件名

xiaoxiao2021-02-28  98

zz   C#根据绝对路径获取 带后缀文件名、后缀名、文件名

1、c#根据绝对路径获取 带后缀文件名、后缀名、文件名。

                string str =" F:\test\Default.aspx";                string filename = System.IO.Path.GetFileName(str);//文件名 “Default.aspx”                string extension = System.IO.Path.GetExtension(str);//扩展名 “.aspx”                string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(str);// 没有扩展名的文件名 “Default”

2、c#根据绝对路径获取 带后缀文件名、后缀名、文件名,使用 Split 函数。

                string str = =" F:\test\Default.aspx";                char[] delimiterChars = { '.', '\\' };                string[] Mystr = str.Split(delimiterChars);                string sheetName = Mystr[Mystr.Length - 2];);// 没有扩展名的文件名 “Default”

转载请注明原文地址: https://www.6miu.com/read-26360.html

最新回复(0)