2011-06-16 91 views
5

我有一个按钮,单击时使用Process.Start,但我从textBox1.Text中选择数据。如何在C中使用Process.Start中的空格处理值#

虽然textBox1.Text这个数据不出来正常,如果有在textBox1.Text

空间

例如textBox1.Text = testing_123工作

虽然textBox1.Text =测试1 2 3不起作用(只会包括 “测试”)

的代码如下:

private void button19_Click(object sender, EventArgs e) 
    { 
     Process.Start("test.exe", textBox1.Text); 
    } 

回答

4

简单地引用这样的ARGS才通过:

private void button19_Click(object sender, EventArgs e) 
{ 
    Process.Start("test.exe", "\"" + textBox1.Text + "\""); 
} 
2

添加引号围绕您的参数字符串。

+3

并检查'textBox1.Text'中是否存在已经存在的引号。 – canon 2011-06-16 21:11:01

0

如果你只是想摆脱空间:

TextBox1.Text.Replace(" ",string.Empty) 

或者,如果你想替换另一个字(下划线),然后请尝试:

TextBox1.Text.Replace(" ","_") 

如果你想包括空格然后@Teoman有你的答案...

这取决于你的意思是“手柄”。

相关问题