如果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暂时得到了想要的结果,可道理上想不明白呀?!
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暂时得到了想要的结果,可道理上想不明白呀?!
解决方案 »
- serialPort.Write(sendBuff, 0, sendBuff.Length);
- js控制session问题
- 请问如何在c#的listview中事先修改数据的功能
- 请问这段代码如何用C#实现?
- winform 中文
- C# 正则表达式。
- 有意组建工作组的朋友们,可以近来看看
- 如何同时移除Listview中的多个行项??
- linq to sql时无法连接数据库
- 那位兄弟知道去哪里可以下载支持C#移动控间的手机模拟器俄!
- 我在作展销系统时,有一页面的背景图是张图片,此图中每个方框都是动态的,有3种方框,白色和黑色方框表示展位没有出租,红色方框表示展位已出租给一个公司,橙色方框表示此展位已由一个公司预定吧,自动显示此公司
- Socket向控件传递信息,使用BackgroundWorker还是Invoke
cmd = str.Trim().Substring(1, str.Trim().Length - 2);
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/