2011-06-16 39 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有你的答案...

這取決於你的意思是「手柄」。