字符串与十六进制互相转换 c#

来源:互联网 发布:python抓取动态网页 编辑:程序博客网 时间:2024/04/29 22:34

public static string Encode(string strEncode)
    {
        string strReturn = "";// 存储转换后的编码
        foreach (short shortx in strEncode.ToCharArray())
        {
            strReturn += shortx.ToString("X4");
        }
        return strReturn;
    }
    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;
    }

原创粉丝点击