zoukankan      html  css  js  c++  java
  • ASCII 转换帮助类

        /// <summary>
        /// ASCII 帮助类
        /// </summary>
        public static class ASCIIHelper
        {
            /// <summary>
            /// 含中文字符串转ASCII
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string Str2ASCII(String str)
            {
                //这里我们将采用2字节一个汉字的方法来取出汉字的16进制码
                byte[] textbuf = Encoding.Default.GetBytes(str);
                //用来存储转换过后的ASCII码
                string textAscii = string.Empty;
    
                for (int i = 0; i < textbuf.Length; i++)
                {
                    textAscii += textbuf[i].ToString("X");
                }
                return textAscii;
            }
    
            /// <summary>
            /// ASCII转含中文字符串
            /// </summary>
            /// <param name="textAscii">ASCII字符串</param>
            /// <returns></returns>
            public static string ASCII2Str(string textAscii)
            {
    
                int k = 0;//字节移动偏移量
                byte[] buffer = new byte[textAscii.Length / 2];//存储变量的字节
                for (int i = 0; i < textAscii.Length / 2; i++)
                {
                    //每两位合并成为一个字节
                    buffer[i] = byte.Parse(textAscii.Substring(k, 2), System.Globalization.NumberStyles.HexNumber);
                    k = k + 2;
                }
                //将字节转化成汉字
                return Encoding.Default.GetString(buffer);
            }
        }
  • 相关阅读:
    cocos2d翻牌效果实现
    ShareSDK
    cocos2diphone版本选择
    UITextView设置透明背景
    iOS常用第三方类库
    CCMenu布局
    macosx下安装mysql
    mac截图
    iPhone对OpenGL ES的支持
    cocos2d下action和线程
  • 原文地址:https://www.cnblogs.com/5tomorrow/p/13346570.html
Copyright © 2011-2022 走看看