如何启动包含引号的 URL? [英] How do you launch a URL that includes quotes?

查看:37
本文介绍了如何启动包含引号的 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to launch a URL from my application that includes quotes, like the following:

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

所以这将在 Google 中搜索:

So this will search Google for:

hello world "带引号的测试"

hello world "test with quotes"

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

I'm opening this in the user's default web browser by using the Process.Start command:

System.Diagnostics.Process.Start(TheURL);

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

However, this command fails to do anything if Firefox is set as my default browser, and it launches three separate tabs if Chrome is my default browser. Does anyone know how you can pass quotes to the Process.Start command?

推荐答案

就个人而言,我喜欢使用 URI.它为编码/解码提供了很大的灵活性,而且几乎不需要任何努力.

Personally, I like to use URI. It allows a lot of flexibility with encoding/decoding and practically no effort.

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

这篇关于如何启动包含引号的 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆