有  string a="\x0002\x0003";
用什么办法,可以直接打印出a并显示 "\x0002\x0003" 这个结果?
(现在显示的是乱码)

解决方案 »

  1.   

     string a = @"\x0002\x0003"; 
      

  2.   

    你过滤 一下吧,  a.Replace ("\","\\");   然后再试试吧
      

  3.   

    a.Replace ("\","\\");  语法都不对。
      

  4.   

    class Program
    {
      static void Main()
      {
        string a = "\x0002\x0003"; 
        string b = System.Uri.EscapeUriString(a);   
        System.Console.WriteLine(b);   // 输出:%02%03
      }
    }
      

  5.   

    using System;
    using System.Text;class Program
    {
      static void Main()
      {
        string a = "\x0002\x0003"; 
        string b = EscapeString(a);   
        Console.WriteLine(b);   // 输出:\x0002\x00033
      }
      
      static string EscapeString(string s)
      {
        StringBuilder sb = new StringBuilder();
        foreach (char c in s)
        {
          sb.AppendFormat("\\x{0:x4}", (int)c);
        }
        return sb.ToString();
      }
    }
      

  6.   

    如果a里面包含的字符串是"\x0002ZA\x0003",转出来的还是不理想,因为我不想把ZA也转成16进制。