Question Opening a new firefox window and searching

womadness

New member
Joined
Mar 3, 2009
Messages
2
Programming Experience
Beginner
I honestly have no idea whether this is the wrong forum or not. But it seems like the most appropiate one.

I'd suppose this would be a very simple question, and I'm a complete newbie at this.

I've got a textbox and a button. I want to be able to put in a keyword(s), for a search. For example on google. I use this:

VB.NET:
    Const GOOGLE_SEARCH As String = "http://www.google.dk/search?q="

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Process.Start("C:\Program Files\Mozilla Firefox\Firefox.exe", GOOGLE_SEARCH & TextBox1.Text)
    End Sub

What I want to do is open a new firefox window and search for the keyword put into "TextBox1". It does work, sorta. The only problem is if I put multiple keywords in (seperated by space). Then it opens 2 windows. 1 with the first word (keyword1 - Google-søgning), and another one (http://keyword2/).

Any ideas on how to fix this?
 
You have to url encode the search string, most importantly to replace spaces with + chars and handle & chars and such, but also encode international chars safely. The simplest way to do this is to add reference to the System.Web library and use the HttpUtility.UrlEncode method. Example:
VB.NET:
Dim searchstring As String = Web.HttpUtility.UrlEncode("this & test æøå")

'= "this+%26+test+%c3%a6%c3%b8%c3%a5"
You can also pass the Http url directly to Process.Start to open in default browser.
 
Back
Top