Process.Start is eating spaces
-
I am trying to launch a Google search for a specific string from with my application, and this is all working perfectly, until the search string contains quotes. If there are quotes in the search string, then all the spaces inside the string are removed. In the debugger, the string looks like this:
http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
But when Google gets it, the URL looks like this:http://www.google.com/search?hl=en&q="JustForLaughsComedyTour"
If there are no quotes around the search string, then it works perfectly. Running it from the command line doesn't work at all unless I remove the quotes around the search string and place them around the entire command. The code I am using is here:System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(strCmd, strArgs); pInfo.Verb = "open"; pInfo.ErrorDialog = true; pInfo.WorkingDirectory = strDir; System.Diagnostics.Process.Start(pInfo);
I realize that I could probably UrlEncode the string or something, but I am using a generic application launcher thingie that doesn't know anything about the application it is launching - it just calls start on whatever string you pass it. Actually, it is a version of the Visual Studio "External Tools" manager that I wrote[^] as a .NET control, so I don't want it to have to treat URLs differently to standard commands, and I don't want the command to be "IExplore.exe" either. I want it to launch the users default browser based on a URL that I give it. Does anyone know how to workaround this quoted search string weirdness, without having to resort to a special case to fix it? Thanks!The StartPage Randomizer - The Windows Cheerleader - Twitter
-
I am trying to launch a Google search for a specific string from with my application, and this is all working perfectly, until the search string contains quotes. If there are quotes in the search string, then all the spaces inside the string are removed. In the debugger, the string looks like this:
http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
But when Google gets it, the URL looks like this:http://www.google.com/search?hl=en&q="JustForLaughsComedyTour"
If there are no quotes around the search string, then it works perfectly. Running it from the command line doesn't work at all unless I remove the quotes around the search string and place them around the entire command. The code I am using is here:System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(strCmd, strArgs); pInfo.Verb = "open"; pInfo.ErrorDialog = true; pInfo.WorkingDirectory = strDir; System.Diagnostics.Process.Start(pInfo);
I realize that I could probably UrlEncode the string or something, but I am using a generic application launcher thingie that doesn't know anything about the application it is launching - it just calls start on whatever string you pass it. Actually, it is a version of the Visual Studio "External Tools" manager that I wrote[^] as a .NET control, so I don't want it to have to treat URLs differently to standard commands, and I don't want the command to be "IExplore.exe" either. I want it to launch the users default browser based on a URL that I give it. Does anyone know how to workaround this quoted search string weirdness, without having to resort to a special case to fix it? Thanks!The StartPage Randomizer - The Windows Cheerleader - Twitter
-
Did you actually try to google that? Replace ' ' with '+'. http://www.google.co.uk/search?q="Just+For+Laughs+Comedy+Tour"[^]
hmmm pie
fly904 wrote:
Replace ' ' with '+'.
I can't, because the code that launches the command doesn't know what sort of command it is. In other words, as far as the launcher knows, these two strings are equivalent and should be treated exactly the same:
http://www.google.co.uk/search?q="Just For Laughs Comedy Tour"
notepad "Just For Laughs Comedy Tour"
Interestingly, if you paste the following command into the Run box in Windows XP it doesn't work either, but if you paste it directly into your browser it works just fine. This leads me to think there's something strange going on inside Windows somwehere.http://www.google.co.uk/search?q="Just For Laughs Comedy Tour"
And just for laughs, try these too:firefox http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
iexplore http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
They both work as expected.The StartPage Randomizer - The Windows Cheerleader - Twitter
-
fly904 wrote:
Replace ' ' with '+'.
I can't, because the code that launches the command doesn't know what sort of command it is. In other words, as far as the launcher knows, these two strings are equivalent and should be treated exactly the same:
http://www.google.co.uk/search?q="Just For Laughs Comedy Tour"
notepad "Just For Laughs Comedy Tour"
Interestingly, if you paste the following command into the Run box in Windows XP it doesn't work either, but if you paste it directly into your browser it works just fine. This leads me to think there's something strange going on inside Windows somwehere.http://www.google.co.uk/search?q="Just For Laughs Comedy Tour"
And just for laughs, try these too:firefox http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
iexplore http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
They both work as expected.The StartPage Randomizer - The Windows Cheerleader - Twitter
I see your point now after testing it. The only way I found was to 'double escape' the speech marks. I just tried this and it worked perfectly after opening in my default browser (firefox).
string searchString = "\\\"Just For Laughs Comedy Tour\\\"";
System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo("http://www.google.co.uk/search?q=" +
searchString.Replace(" ", "+"));
pInfo.Verb = "open";
pInfo.ErrorDialog = true;
System.Diagnostics.Process.Start(pInfo);There's a part of me which hate's seeing spaces in URL's.
hmmm pie