获得除去后缀后的仅文件名

2015-12-20 10:21:05  访问(1584) 赞(0) 踩(0)


        /// <summary>
        /// 获得除去后缀后的仅文件名
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        protected 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;
        }


标签:获得除去后缀后的仅文件名 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)