文件获得除去后缀后的仅文件名 - FileOnlyNameGet
2017-02-01 18:23:29 访问(1923) 赞(0) 踩(0)
-
/// <summary>
/// 获得除去后缀后的仅文件名
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public string FileOnlyNameGet(string fileName)
{
if (fileName == null || fileName.Length == 0)
return "";
int idxOne = fileName.LastIndexOf('/');
int idxTwo = fileName.LastIndexOf('\\');
if (idxOne != -1)
{
if (idxTwo > idxOne)
fileName = fileName.Substring(idxTwo + 1);
else
fileName = fileName.Substring(idxOne + 1);
}
else
{
if (idxTwo != -1)
fileName = fileName.Substring(idxTwo + 1);
}
int idx = fileName.LastIndexOf('.');
if (idx != -1)
fileName = fileName.Substring(0, idx);
return fileName;
}
-
标签:
C# 


后缀名 


文件名称 


获得文件名 


上一条:
下一条:
相关评论
发表评论