zoukankan      html  css  js  c++  java
  • 字符串和十六进制之间的转换方法实例

    这篇文章介绍了字符串和十六进制之间的转换方法实例,有需要的朋友可以参考一下
    复制代码代码如下:

    /// <summary>
            /// <函数:Encode>
            /// 作用:将字符串内容转化为16进制数据编码,其逆过程是Decode
            /// 参数说明:
            /// strEncode 需要转化的原始字符串
            /// 转换的过程是直接把字符转换成Unicode字符,比如数字"3"-->0033,汉字"我"-->U+6211
            /// 函数decode的过程是encode的逆过程.
            /// </summary>
            /// <param name="strEncode"></param>
            /// <returns></returns>
            public static string Encode(string strEncode)
            { // www.jbxue.com
                string strReturn = "";//  存储转换后的编码
                foreach (short shortx in strEncode.ToCharArray())
                {
                    strReturn += shortx.ToString("X4");
                }
                return strReturn;
            }
            /// <summary>
            /// <函数:Decode>
            ///作用:将16进制数据编码转化为字符串,是Encode的逆过程
            /// </summary>
            /// <param name="strDecode"></param>
            /// <returns></returns>
            public static string Decode(string strDecode)
            {
                string sResult = "";
                for (int i = 0; i < strDecode.Length / 4; i++)
                {
                    sResult += (char)short.Parse(strDecode.Substring(i * 4, 4), global::System.Globalization.NumberStyles.HexNumber);
                }
                return sResult;
            }

  • 相关阅读:
    findall查找 ^$*+?{ }{m,n}[].[.] w s d  D W
    find查找、split分隔、replace替换
    round四舍五入
    pow求一个数的n次幂
    iter创建一个可以被迭代的对象
    notepad++ gmt中文乱码问题
    matlab eps 字体用AI打开乱码的解决
    [转载]Matlab中使用xlswrite函数时出现服务器出现异常的解决方法
    How to determine which grid cells a line segment passes through?
    matlab给定点生成多边形,多边形掩膜处理
  • 原文地址:https://www.cnblogs.com/linuxnotes/p/3411667.html
Copyright © 2011-2022 走看看