/// <summary>
/// <函數(shù):Encode>
/// 作用:將字符串內(nèi)容轉(zhuǎn)化為16進(jìn)制數(shù)據(jù)編碼,其逆過程是Decode
/// 參數(shù)說明:
/// strEncode 需要轉(zhuǎn)化的原始字符串
/// 轉(zhuǎn)換的過程是直接把字符轉(zhuǎn)換成Unicode字符,比如數(shù)字"3"-->0033,漢字"我"-->U+6211
/// 函數(shù)decode的過程是encode的逆過程.
/// </summary>
/// <param name="strEncode"></param>
/// <returns></returns>
public static string Encode(string strEncode)
{
string strReturn = "";// 存儲(chǔ)轉(zhuǎn)換后的編碼
foreach (short shortx in strEncode.ToCharArray())
{
strReturn += shortx.ToString("X4");
}
return strReturn;
}
/// <summary>
/// <函數(shù):Decode>
///作用:將16進(jìn)制數(shù)據(jù)編碼轉(zhuǎn)化為字符串,是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;
}