string s1 = "\x00\x00\x00\x00\x00\x24\xea\x38";
string s2 = "\\x00\\x00\\x00\\x00\\x00\\x24\\xea\\x38";上面2个字符串,怎么把s2转换成s1的样子??请高手赐教。。具体情况描述: s1是我从网页中截取出来的,网站上就显示为“\x00\x00\x00\x00\x00\x24\xea\x38”,可是保存到字符串中,就变成s2的样子了。可是我要用的是s1的样子,不知道怎么转换。

解决方案 »

  1.   

    假如你是在 VS 的监视窗口里看是 s2 的样子,那没关系的,实际值还是 s1 ,只是显示的时候加上了转义字符
      

  2.   

    s2的值就是s1,输出一下看看就知道了
    s1这个字符串,如果不加@,肯定输出乱码了
      

  3.   


    我最终要的是s1的值,因为s1和s2是完全不同的字符串。你可以两个都输出看下,是不一样的。
      

  4.   


                string s1 = @"\x00\x00\x00\x00\x00\x24\xea\x38";
                s1 = s1.Replace("\\", @"\\");
                MessageBox.Show(s1);
      

  5.   


    转换完成"\\\\x00\\\\x00\\\\x00\\\\x00\\\\x00\\\\x24\\\\xea\\\\x38"这样的了
      

  6.   

    string s3 = new string(
        s2.Split('\\').Skip(1).Select((o) => 
        { 
            return (char)short.Parse(o.Replace("x", ""), System.Globalization.NumberStyles.AllowHexSpecifier); 
        }).ToArray());
    s3就是像s1那样的乱码。只是我想知道lz要这样的乱码来干嘛?
      

  7.   

    自己解决了,s1是十六进制的,我要的是得到他的值,靠replace是不可能得到的。我的解决办法如下:
    1:先把s2 拆分成数组 得到 00 00 00 00 00 24 ea 38
    2:得到对应的10进制值 分别为 0 0 0 0 0 36 234 56
    3:然后得到对应的ascii值 分变为 \0 \0 \0 \0 \0 $ ê 8
    4:最后的组合成字符串,最后的值就是 "\0\0\0\0\0$ê8""\x00\x00\x00\x00\x00\x24\xea\x38" 等价于 "\0\0\0\0\0$ê8"结贴了,虽然没解决问题,还是谢谢大家的帮助。
      

  8.   


    出错啊,说System.Array不包含Skip的定义
      

  9.   

    那这样吧    string s3 = new string(
            Array.ConvertAll(
                Array.FindAll(s2.Split('\\'),
                new Predicate<string>(delegate(string s) {
                    return !string.IsNullOrEmpty(s); 
                })), 
                delegate(string s) 
                { 
                    return (char)short.Parse(s.Replace("x", ""), System.Globalization.NumberStyles.AllowHexSpecifier); 
                })
            );