ANSI字符串转化成unicode字符串

joyhen 2011-08-26 11:39:09
一个unicode字符串,转换成ANSI字符串以实现

public static string UnicodeToAscii(string paramstr)
{
if (paramstr.Length > 0)
{
byte[] array = System.Text.Encoding.ASCII.GetBytes(paramstr);
string str = null;
for (int i = 0; i < array.Length; i++)
{
int asciicode = (int)(array[i]);
str += Convert.ToString(asciicode);
}
return str;
}
else
{
throw new Exception("Unciode Code is not valid.");
}
}

如何再将上面的 str 转回来呢,
求详细代码,立马结贴
...全文
47 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
joyhen 2011-08-27
  • 打赏
  • 举报
回复
谢谢,我也是昨天下午测试才知道,ASCII和ANSI不一样
[Quote=引用 2 楼 ojlovecd 的回复:]

这明明是Unicode转ASCII……而不是ANSI……
C# code

public static string AsciiToUnicode(string paramstr)
{
return System.Text.Encoding.Unicode.GetString(System.Text.Encoding.ASCII.Get……
[/Quote]
我姓区不姓区 2011-08-26
  • 打赏
  • 举报
回复
这明明是Unicode转ASCII……而不是ANSI……

public static string AsciiToUnicode(string paramstr)
{
return System.Text.Encoding.Unicode.GetString(System.Text.Encoding.ASCII.GetBytes(paramstr));
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧