asp.net实现调用百度pai 在线翻译英文转中文
2012-12-18 14:09:40 来源:WEB开发网核心提示:Regex regex = new Regex(pattern);HTML = regex.Replace(HTML, "");return HTML;}//中文转为UNICODE字符 forget neverpublic string ctu(string str){string outStr =
Regex regex = new Regex(pattern);
HTML = regex.Replace(HTML, "");
return HTML;
}
HTML = regex.Replace(HTML, "");
return HTML;
}
//中文转为UNICODE字符 forget never
public string ctu(string str)
{
string outStr = "";
if (!string.IsNullOrEmpty(str))
{
for (int i = 0; i < str.Length; i++)
{
//将中文字符转为10进制整数,然后转为16进制unicode字符
outStr += "\\u" + ((int)str[i]).ToString("x");
}
}
return outStr;
}
//UNICODE字符转为中文
public string utc(string str)
{
string outStr = "";
if (!string.IsNullOrEmpty(str))
{
string[] strlist = str.Replace("\\", "").Split('u');
try
{
for (int i = 1; i < strlist.Length; i++)
{
//将unicode字符转为10进制整数,然后转为char中文字符 asp.net
outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber);
}
}
catch (FormatException ex)
{
outStr = ex.Message;
}
}
return outStr;
}
}
}
更多精彩
赞助商链接