各位大虾,
         
       请教一个使用转移符的问题:
strFtpCmdFile = "d:\abc prm\*.*";
strCmd = "/c FTP -v -i -s:"+strFtpCmdFile;这样的话,strCmd的值最后是"/c FTP -v -i -s d:\abc prm\*.*".但我想把最后结果变成 "/c FTP -v -i -s "d:\abc prm\*.*"",也就是说把strFtpCmdFile 的值用一对双引号引起来,怎么做?      请各位大虾帮忙,谢谢!

解决方案 »

  1.   

    strCmd = "/c FTP -v -i -s:\""+strFtpCmdFile +"\"" ;
      

  2.   

    fengfangfang(),按照您的方法,最后结果是:
    "/c FTP -v -i -s:\"D:\\ABC PRM\\TestForBatch\\BatchTradeData\\Batch_ftp.txt\""
      

  3.   

    这样的话,strCmd的值最后是"/c FTP -v -i -s d:\abc prm\*.*".但我想把最后结果变成 "/c FTP -v -i -s "d:\abc prm\*.*"",
    strFtpCmdFile = "\"d:\abc prm\*.*\"";但是解决不了socket send 的问题,我也在做ftp,不过不是自己做双方,发送汉字过去根本不认通过码制转换也不能实现。晕啊 ……
      

  4.   

    这样做: "/c FTP -v -i -s \"d:\\abc prm\\*.*\""
      

  5.   

    strFtpCmdFile = "d:\\abc prm\\*.*";
    strCmd = "/c FTP -v -i -s: \""+ strFtpCmdFile + "\"";
      

  6.   


    to  kkk_visual(宇宙中我是最厉害的!哈哈(但不包括地球):  
    按照您的方法,最后结果是:
    "/c FTP -v -i -s: \"D:\\\\ABC PRM\\\\TestForBatch\\\\BatchTradeData\\\\\\Batch_ftp.txt\""
      

  7.   

    to fd7893(看着办吧) 麻烦您详细说一下啦,小弟着急的很哪
      

  8.   

    你最后不是想得到这样的结果吗"/c FTP -v -i -s "d:\abc prm\*.*""
    直接:
    strCmd = @"/c FTP -v -i -s "d:\abc prm\*.*"";
    就可以了
      

  9.   

    或者 strCmd = string.Format("/c FTP -v -i -s \"{0}\"",strFtpCmdFile );
      

  10.   

    to fd7893(看着办吧) 你这是直接知道strFtpCmdFile的值的操作,
    请问如何在 strCmd = "/c FTP -v -i -s:"+strFtpCmdFile; 这个语句中操作阿?
      

  11.   

    to fd7893(看着办吧) strCmd = string.Format("/c FTP -v -i -s \"{0}\"",strFtpCmdFile );的结果是:
    "/c FTP -v -i -s \"D:\\ABC PRM\\TestForBatch\\BatchTradeData\\Batch_ftp.txt\""
      

  12.   

    private void test()
    {
    string strFtpCmdFile =@"d:\abc prm\*.*";
    string strCmd = "/c FTP -v -i -s:";
    string strCmdvalue=strCmd+((char)34).ToString()+strFtpCmdFile+((char)34).ToString();
    MessageBox.Show(strCmdvalue);
    }
    //测试通过,接分,哈哈
      

  13.   

    to dlzhangln(我知道你性格,答题要给分的,你也磨不开不给,是不?)
    我用您的方法,结果是:"/c FTP -v -i -s:\"d:\\abc prm\\*.*\""您再给瞧瞧吧。谢谢了
      

  14.   

    这个结果用MessageBox表示出来确实是/c FTP -v -i -s:"d:\abc prm\*.*\", 但小弟要直接用这个字符串啊。怎么办哪?
      

  15.   

    我直接用您的函数试验了一把,MessageBox的结果确实是对的,但小弟要用这个字符串(就是您的strCmdvalue)啊,它的值是"/c FTP -v -i -s:\"d:\\abc prm\\*.*\""
      

  16.   

    这样,生成的字符串多多了\你给替换掉就行了,reg.Replace(strCmdvalue,"^\\$","")
      

  17.   

    不好意思写错了,reg.Replace(strCmdvalue,"\\","")
      

  18.   

    不好意思写错了,reg.Replace(strCmdvalue,"\\","")那前后多出来的那两个“\”呢?
      

  19.   

    晕~
    lz上面的就写错了\,要转义的啊
    string strFtpCmdFile ="\"d:\\abc prm\\*.*\"";
    string strCmd = "/c FTP -v -i -s:"+strFtpCmdFile;
      

  20.   

    晕,也不行,看来还得期待高手了,MessageBox出得结果是正确的,竟然没想到单独字符串这种情况,惭愧。
      

  21.   

    to jingtao_zhou(小熊) ,谢谢您的关注。
    您这是知道了strFtpCmdFile 的值才做的转义,我那strFtpCmdFile 是从config读近来的,所以关键是在strCmd = "/c FTP -v -i -s:"+strFtpCmdFile;这句话上下功夫啊。唉,这个问题真的解决不了了吗?
      

  22.   

    晕死 自己运行看下面代码strCmd值是什么 string strFipCmdFile = @"d:\abc prm\*.*";
     string strCmd = string.Format("/c FTP -v -i -s \"{0}\"", strFipCmdFile);
     Console.WriteLine(strCmd);
      

  23.   

    to
    晕死 自己运行看下面代码strCmd值是什么 string strFipCmdFile = @"d:\abc prm\*.*";
     string strCmd = string.Format("/c FTP -v -i -s \"{0}\"", strFipCmdFile);
     Console.WriteLine(strCmd);——————————————————————————strCmd的值是 "/c FTP -v -i -s \"d:\\abc prm\\*.*\"",您是不是用MessageBox秀了一下?那样确实是正确的,可是这个字符串我要直接用阿。
      

  24.   

    to
    晕死 自己运行看下面代码strCmd值是什么 string strFipCmdFile = @"d:\abc prm\*.*";
     string strCmd = string.Format("/c FTP -v -i -s \"{0}\"", strFipCmdFile);
     Console.WriteLine(strCmd);——————————————————————————strCmd的值是 "/c FTP -v -i -s \"d:\\abc prm\\*.*\"",您是不是用MessageBox秀了一下?那样确实是正确的,可是这个字符串我要直接用阿。
      

  25.   

    strCmd的值是 "/c FTP -v -i -s \"d:\\abc prm\\*.*\"",您是不是用MessageBox秀了一下?那样确实是正确的,可是这个字符串我要直接用阿。-------------------------------------------------那就是可以直接用的 !
      

  26.   

    strCmd = "/c FTP -v -i -s:\""+strFtpCmdFile +"\"" ;
      

  27.   

    StringBuilder sb = new StringBuilder();
    sb.Append(string.Format("/c FTP -v -i -s ")).Append((char)0x22).Append("d:").Append((char)0x5c).Append("abc prm").Append((char)0x5c).Append("*.*").Append((char)0x22);
                string str = sb.ToString();
    可以了
      

  28.   

    0x22 是"的ASCII码
    0x5c 是\的ASCII码
      

  29.   

    StringBuilder sb = new StringBuilder();
    sb.Append(string.Format("/c FTP -v -i -s ")).Append((char)0x22).Append("d:").Append((char)0x5c).Append("abc prm").Append((char)0x5c).Append("*.*").Append((char)0x22);
                string str = sb.ToString();
    可以了
    ————————
    晕,我的路径是读出来的,不一定非是d:\\abc prm\\*.*啊
      

  30.   

    忘了说: 只要 sb.ToString() 结果就又变成了"/c FTP -v -i -s \"d:\\abc prm\\*.*\""String 存不了/c FTP -v -i -s:"d:\abc prm\*.*\" 这种形式
      

  31.   


    所以 你要不用 StringBuider 要不就用 char[] 做吧To:
    晕,我的路径是读出来的,不一定非是d:\\abc prm\\*.*啊
    -----------------------------
    Append("abc prm")中"abc prm"可以换成变量,
    Append((char)0x5c)也可以用循环来加啊
      

  32.   

    strCmd = string.Format("/c FTP -v -i -s \'{0}\'",strFtpCmdFile );
      

  33.   

    http://community.csdn.net/Expert/topic/4983/4983948.xml?temp=.7148706