Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#打开带有插入单词的浏览器_C#_Url_Browser_Textbox - Fatal编程技术网

C#打开带有插入单词的浏览器

C#打开带有插入单词的浏览器,c#,url,browser,textbox,C#,Url,Browser,Textbox,我想问你们是否有可能做到以下几点: 在文本框中键入类似“搜索冥王星”的内容 然后它必须搜索最后一个词 我就是这样做的,但它不起作用,因为当我这样做的时候 我的浏览器打开两次。 带“”的一个 另一个打开的标签是我写的单词 文本框。有人能帮我解决这个问题吗 这是用于此的代码: string url = "https://www.google.be/# if (inputTBX.Text.Contains("search ") == true) { inputTBX.Text.Replace

我想问你们是否有可能做到以下几点: 在文本框中键入类似“搜索冥王星”的内容 然后它必须搜索最后一个词

我就是这样做的,但它不起作用,因为当我这样做的时候 我的浏览器打开两次。
带“”的一个 另一个打开的标签是我写的单词 文本框。有人能帮我解决这个问题吗

这是用于此的代码:

string url = "https://www.google.be/#

if (inputTBX.Text.Contains("search ") == true)
{
    inputTBX.Text.Replace("search ", "");
    string URL = url += inputTBX.Text;
    Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
    URL);
    inputTBX.Clear();
}

就像在一个简单的控制台应用程序中进行的测试一样,我尝试了以下方法,并成功地启动了我的默认浏览器

var t = "pluto";
Process.Start("http://google.com/search?q=" + t);
这同样有效

var t = "pluto";
Process.Start("https://www.google.be/search?q=" + t);
在本例中,您需要将查询字符串设置为

您的第一个问题是,您正在尝试使用Replace方法,但是您需要将它分配到某个地方。这里是刚刚测试的代码的工作解决方案。请注意,我所做的不同之处

inputTBX.Test = "search pluto";
string url = "https://www.google.be/search?q=";

if (inputTBX.Contains("search "))
{
    inputTBX.Text = inputTBX.Replace("search ", "");
    string URL = url += inputTBX;
    Process.Start(URL); // this will launch your default web browser
    inputTBX.Clear();
}

因为您的查询字符串中有“搜索”一词。。如果(inputbx.Contains(“search”),你真的不需要这行代码,但是如果你把它保留下来,如果你通过了
搜索行星冥王星
,例如在你的文本框中,这行代码就会起作用,就像在一个简单的控制台应用程序中进行测试一样。我尝试了以下步骤,它启动了我的默认浏览器

var t = "pluto";
Process.Start("http://google.com/search?q=" + t);
这同样有效

var t = "pluto";
Process.Start("https://www.google.be/search?q=" + t);
在本例中,您需要将查询字符串设置为

您的第一个问题是,您正在尝试使用Replace方法,但是您需要将它分配到某个地方。这里是刚刚测试的代码的工作解决方案。请注意,我所做的不同之处

inputTBX.Test = "search pluto";
string url = "https://www.google.be/search?q=";

if (inputTBX.Contains("search "))
{
    inputTBX.Text = inputTBX.Replace("search ", "");
    string URL = url += inputTBX;
    Process.Start(URL); // this will launch your default web browser
    inputTBX.Clear();
}
因为您的查询字符串中有“搜索”一词。。如果(inputbx.Contains(“search”)你真的不需要这一行
,但是如果你把它保留下来,如果你通过
搜索行星冥王星
,例如在你的文本框中,它就会起作用

inputTBX.Text.Replace("search ", "");
非常糟糕,因为如果您有这样的输入字符串,它将无法完成其工作

"search research on Beethoven's work"
如果您希望关键短语是“搜索”,则应该这样做

inputTBX.Text.Substring(("search ").Length); //this way it will skip the "search " phrase and use the rests of the phrase for searching
对于给定URL的流程,只需执行以下操作

string url = "https://www.google.be/#q="; //notice the q= is missing in your code shown
Process.Start(url + inputTBX.Text.Substring(("search ").Length));
这部分

inputTBX.Text.Replace("search ", "");
非常糟糕,因为如果您有这样的输入字符串,它将无法完成其工作

"search research on Beethoven's work"
如果您希望关键短语是“搜索”,则应该这样做

inputTBX.Text.Substring(("search ").Length); //this way it will skip the "search " phrase and use the rests of the phrase for searching
对于给定URL的流程,只需执行以下操作

string url = "https://www.google.be/#q="; //notice the q= is missing in your code shown
Process.Start(url + inputTBX.Text.Substring(("search ").Length));


你的问题与任何被标记的东西的关系都比命令行开关Chrome允许的要小…你的问题与任何被标记的东西的关系都比命令行开关Chrome允许的要小…嘿,thx for awnsering,但是我得到了一个错误:无法从“string”转换为“System.Windows.Forms.Control”@ZionMees看看更新..
inputbx.Text=inputbx.Replace(“搜索”,替换)
需要查看
.Text
属性它是
inputbx
是一个输入错误。。答案是,请让我知道这是否解决了问题。我现在使用了你的部分代码和下面的部分代码。谢谢您的帮助。@ZionMees那么您应该将其标记为可接受的答案,因为我向您展示的内容实际上可以用于awnsering的Hey thx,但这是我得到的一个错误:无法从“字符串”转换为“System.Windows.Forms.Control”@ZionMees查看更新..
inputbx.Text=inputbx.Replace(“搜索”)
需要查看
.Text
属性它是
inputbx
是一个输入错误。。答案是,请让我知道这是否解决了问题。我现在使用了你的部分代码和下面的部分代码。谢谢你的帮助。@ZionMees那么你应该将它标记为可接受的答案,因为我向你展示的东西实际上是有效的。谢谢你的回答。我尝试过这个,但我遇到了一个错误:对此我能做些什么?不,它不应该像那样使用。它用于为查询的输入创建字符串,因为.Substring结果是字符串类型。if语句参数必须保持布尔值。因此,您仍然可以使用您的if条件:if(inputbx.Text.Contains(“search”)==true),但对于替换,您应该使用我的(.Substring)更改它。我很高兴您发现它很有用。当你不是真的想替换时,要小心使用
Replace
(它会替换整个字符串,而你只想替换前面的部分!)。您还有另一个选项
。Substring
可以执行此操作。感谢您的提醒,我尝试了此操作,但出现了一个错误:对此我能做些什么?不,不应该这样使用。它用于为查询的输入创建字符串,因为.Substring结果是字符串类型。if语句参数必须保持布尔值。因此,您仍然可以使用您的if条件:if(inputbx.Text.Contains(“search”)==true),但对于替换,您应该使用我的(.Substring)更改它。我很高兴您发现它很有用。当你不是真的想替换时,要小心使用
Replace
(它会替换整个字符串,而你只想替换前面的部分!)。您还有另一个选项
.Substring