Tom
Tom

Reputation: 441

Implementing search box in my Java program

I am making simple browser. I want to implement a search box which will automatically redirect to the results of search for example in http://uk.ask.com/ it looks quite simple.

If I was going to search for "hello SO" it link would look like this.

http://uk.ask.com/web?qsrc=1&o=0&l=dir&q=hello+SO+&dm=all

So what I am wanting to do is make a JTextField where user can enter what he is searching for, and then just fill in whatever he typed into the url

http://uk.ask.com/web?qsrc=1&o=0&l=dir&q="FILL HERE WITH + instead of spaces "&dm=all

I don't know how to split the string entered and fill the spaces with + signs. Any idea ? Also this is just the way I thought it would be possible to do it. I would much appreciate any other suggestions. Thanks in advance

Upvotes: 2

Views: 261

Answers (2)

SLaks
SLaks

Reputation: 888303

You need to URL encode the string.

Upvotes: 4

Jayamohan
Jayamohan

Reputation: 12924

Here you go

url.replace(" ", "+");

Upvotes: 1

Related Questions