编码转换
gb2312string="中国"
System.Web.HttpUtility.UrlEncode(gb2312string, System.Text.Encoding.GetEncoding("utf-8"))
结果:%e4%b8%ad%e5%9b%bd
using Microsoft.JScript;
//用 Microsoft.JScript 编码 方便前台的 javascript 调用
string Result = Microsoft.JScript.GlobalObject.encodeURIComponent("中国");
结果:%E4%B8%AD%E5%9B%BD
char[] chars = { '\u56DE', '\u6C11', '\u4E2D', '\u5B66' };
string strng = new String(chars);
结果:回民中学
当input 为'\u56DE\u6C11\u4E2D\u5B66',转化为回民中学
public string ToSBC(string input)
{
//半角转全角:
char[] c = input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i] == 32)
{
c[i] = (char)12288; continue;
}
if (c[i] < 127) c[i] = (char)(c[i] + 65248);
}
return new string(c);
}