unity中文乱码问题

///

/// UCS2编码

///

/// UTF-16BE编码的源串

/// 编码后的UCS2串

public static string EncodeUCS2(string src)

{

StringBuilder builer = new StringBuilder();

builer.Append("000800");

byte[] tmpSmsText = Encoding.Unicode.GetBytes(src);

builer.Append(tmpSmsText.Length.ToString("X2")); //正文内容长度

for (int i = 0; i < tmpSmsText.Length; i += 2) //高低字节对调

{

builer.Append(tmpSmsText[i + 1].ToString("X2"));//("X2")转为16进制

builer.Append(tmpSmsText[i].ToString("X2"));

}

builer = builer.Remove(0, 8);

 

return builer.ToString();

}

 

 

///

/// UCS2编码

///

/// UTF-16BE编码的源串

/// zhege 编码后的UCS2串

public static string EncodeUCS2Char(string src)

{

string builerstr = EncodeUCS2(src);

StringBuilder builer = new StringBuilder();

 

for (int i=0;i< builerstr.Length/4;i++) {

string str= string.Format(@"\u{0}", builerstr.Substring(i*4,4));

builer.Append(str);

}

 

return builer.ToString();

}

 

调用EncodeUCS2Char,过去是unicode编码

你可能感兴趣的:(unity,c#)