您的位置:首页 > 其它

字符串格式转换

2016-07-26 11:21 169 查看
        #region Unicode转中文=================================

        public static string Unic2Chinese(string str)

        {

            string outStr = "";

            Regex reg = new Regex(@"(?i)\\u([0-9a-f]{4})");

            outStr = reg.Replace(str, delegate (Match m1)

            {

                return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString();

            });

            return outStr;

        }

        #endregion

        /// <summary>

        /// 替换扩展名

        /// </summary>

        public static string GetUrlExtension(string urlPage, string staticExtension)

        {

            int indexNum = urlPage.LastIndexOf('.');

            if (indexNum > 0)

            {

                return urlPage.Replace(urlPage.Substring(indexNum), "." + staticExtension);

            }

            return urlPage;

        }

        /// <summary>

        /// 删除单个文件

        /// </summary>

        /// <param name="_filepath">文件相对路径</param>

        public static bool DeleteFile(string _filepath)

        {

            if (string.IsNullOrEmpty(_filepath))

            {

                return false;

            }

            string fullpath = GetMapPath(_filepath);

            if (File.Exists(fullpath))

            {

                File.Delete(fullpath);

                return true;

            }

            return false;

        }

        /// <summary>

        /// 获得当前绝对路径

        /// </summary>

        /// <param name="strPath">指定的路径</param>

        /// <returns>绝对路径</returns>

        public static string GetMapPath(string strPath)

        {

            if (strPath.ToLower().StartsWith("http://"))

            {

                return strPath;

            }

            if (HttpContext.Current != null)

            {

                return HttpContext.Current.Server.MapPath(strPath);

            }

            else //非web程序引用

            {

                strPath = strPath.Replace("/", "\\");

                if (strPath.StartsWith("\\"))

                {

                    strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');

                }

                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: