通过完整路径(包括网页路径),获得文件名

2015-12-03 15:46:17  访问(1940) 赞(0) 踩(0)


        /// <summary>
        /// 通过完整路径(包括网页路径),获得文件名
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string ToFileName(string str)
        {
            int idxOne = str.LastIndexOf("/");
            int idxTwo = str.LastIndexOf("\\");

            if (idxOne == -1 && idxTwo == -1)
            {
                return str;
            }

            if (idxTwo > idxOne)
                return str.Substring(idxTwo + 1);
            else
                return str.Substring(idxOne + 1);

        }


标签:常用代码    GetFileName    获得文件名    ToFileName    C# 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)