如何启动包含引号的URL?

我需要从我的应用程序中启动一个包含引号的URL,如下所示:

string TheURL = "http://www.google.com/search?hl=en&q=hello world \"" + "test with quotes\""; 

因此,这将搜索谷歌:

你好世界“用引号测试”

我使用Process.Start命令在用户的默认Web浏览器中打开它:

 System.Diagnostics.Process.Start(TheURL); 

但是,如果将Firefox设置为我的默认浏览器,则此命令无法执行任何操作,如果Chrome是我的默认浏览器,则会启动三个单独的选项卡。 有谁知道如何将引号传递给Process.Start命令?

就个人而言,我喜欢使用URI 。 它允许编码/解码具有很大的灵活性,而且几乎不费吹灰之力。

  Uri myUri = new Uri("http://google.com/search?hl=en&q=\"hello world\""); System.Diagnostics.Process.Start(myUri.AbsoluteUri); 

编辑:应用评论者的建议!

您使用Uri.EscapeUriString : http : //msdn.microsoft.com/en-us/library/system.uri.escapeuristring.aspx

 string search = @"Bill & Ted's Excellent Adventure"; string ActualURL = "http://www.google.com/search?hl=en&q=" + Uri.EscapeDataString(search); System.Diagnostics.Process.Start(ActualURL); 

编辑2:显然我的代码被破坏了。 它不允许包含&符号的搜索。 修正了上面的代码; 现在适用于带有&符号的常规代码和代码。

这不是有效的URL,您无法打开/启动它。

使用System.Web.HttpUtility.UrlEncode在编写组件之前对URL进行编码。

参考: http : //msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx