How to handle values ​​with spaces in Process.Start in C #

I have a button and I use Process.Start when I click on it, although I select the data from textBox1.Text.

Although this data in textBox1.Text does not display correctly if there are spaces in textBox1.Text

eg. textBox1.Text = testing_123 works

although textBox1.Text = testing 1 2 3 does not work (it will only include “testing”)

Code below:

    private void button19_Click(object sender, EventArgs e)
    {
        Process.Start("test.exe", textBox1.Text);
    }
+5
source share
3 answers

Just quote such arguments before passing:

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

Add quotation marks around the argument string.

+2
source

:

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

, (), :

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

, @Teoman ...

, "handle".

0

All Articles