如果CommandLine中包含有空格,比如Documents and Settings ,那么系统就会在你要的路径两端加上一对""。使用CommandLine时需要去掉可能存在的""       string str = Environment.CommandLine;
      string cmd="";      if (str.IndexOf('"') == 0)
      {
         cmd = str.Substring(1, str.Length - 2);
      }
  
这代码理论上没问题啊,先这样试验下:string str="\"C:\\Documents and Settings\\My Documents\\Visual Studio 2005\\Projects\\RichEditTest\\bin\\Debug\\RichEditTest.exe\""      string cmd="";      if (str.IndexOf('"') == 0)
      {
         cmd = str.Substring(1, str.Length - 2);
      }输出cmd,得到:
C:\Documents and Settings\My Documents\Visual Studio 2005\Projects\RichEditTest\bin\Debug\RichEditTest.exe
OK。正式上阵,把字符串常量换成Environment.CommandLine,其它不变。输出是:C:\Documents and Settings\My Documents\Visual Studio 2005\Projects\RichEditTest\bin\Debug\RichEditTest.exe"不同之处是最后多了个"号
我百思不得其解呀,这个尾巴咋来的呢?我用str.Length - 3暂时得到了想要的结果,可道理上想不明白呀?!