本帖最后由 cload 于 2015-10-23 12:53 编辑
[C#] 纯文本查看 复制代码
#region GB2312转Unicode
/// <summary>
/// 单个汉字转换为%AB%CD格式,如"我=%CE%D2"
/// </summary>
/// <param name="Source"></param>
/// <returns></returns>
public static string GB2Unicode(string source)
{
string retStr = "";
string tem = "";
byte[] Bytes = Encoding.GetEncoding("GB2312").GetBytes(source);
for (int i = 0; i < Bytes.Length; i++)
{
if (Bytes[i] >= 48 && Bytes[i] <= 57 || Bytes[i] >= 65 && Bytes[i] <= 90 || Bytes[i] >= 97 && Bytes[i] <= 122)
tem = ((char)(Bytes[i])).ToString();
else
tem = "%" + Bytes[i].ToString("X");
retStr += tem;
}
return retStr;
}
#endregion
|