public string Transtonormalcode(string source)
{
string  transedstring = source;
byte[] sourcebyte=System.Text.Encoding.ASCII.GetBytes(source);
for(int i=0;i<sourcebyte.Length;i++)
{
if(sourcebyte[i]==16)//如果是特殊的命令符号
{
sourcebyte[i]=62;//那么修改成为大于号
}
else if(sourcebyte[i]==0x1c||sourcebyte[i]==0x1d)//如果是闪烁的字体,转换为空格
{
sourcebyte[i]=0x20;
}
}
transedstring = Encoding.ASCII.GetString( sourcebyte, 0, sourcebyte.Length );
return transedstring;
}
该段代码是为了替换一些特殊的字符,但是转回去的时候中午字符都不正常了,请问如何解决。怎么才能把ascII码专程正常的中文

解决方案 »

  1.   

    byte[] sourcebyte=System.Text.Encoding.ASCII.GetBytes(source);
    transedstring = Encoding.ASCII.GetString( sourcebyte, 0, sourcebyte.Length );
    ----------------------------------------------改为
    byte[] sourcebyte = System.Text.Encoding.UTF8.GetBytes(source);
    transedstring = Encoding.UTF8.GetString(sourcebyte, 0, sourcebyte.Length);
      

  2.   

    // 其实你那个函数这样写就可以了:public string Transtonormalcode(string source)
    {
      return source.Replace('\x10', '>').Replace('\x1c', ' ').Replace('\x1d', ' ');
    }