永远的SKYFEI
喜欢在阳光下,光着脊梁,挥汗如雨地工作,每次回头擦汗,看到的都是成就!

 转自百度博客: http://hi.baidu.com/zzticzh/blog/item/0ffbdd8856b92890a5c2722d.html

没想到百度也有这么专业的博主   

 

//中文转为UNICODE字符

string str = "中文";
            string outStr = "";
            if (!string.IsNullOrEmpty(str))
            {               
                for (int i = 0; i < str.Length; i++)
                {
                    //将中文字符转为10进制整数,然后转为16进制unicode字符
                    outStr += "http://www.cnblogs.com/skyfei/admin/file://u/" + ((int)str[i]).ToString("x");
                }
            }

 

 

//UNICODE字符转为中文

            string str = "http://www.cnblogs.com/skyfei/admin/file://u4e2d//u6587";
            string outStr = "";
            if (!string.IsNullOrEmpty(str))
            {
                string[] strlist = str.Replace("http://www.cnblogs.com/skyfei/admin/file://%22,%22%22).split(%20u%20/);
                try
                {
                    for (int i = 1; i < strlist.Length; i++)
                    {
                        //将unicode字符转为10进制整数,然后转为char中文字符
                        outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber);
                    }
                }
                catch (FormatException ex)
                {
                    outStr = ex.Message;
                }
            }

posted on 2008-08-01 10:12  skyfei  阅读(3581)  评论(3编辑  收藏  举报