Firstly, I know that there are other similar messages, but since mine uses the URL, and I'm not always sure what my separator will be, I feel like I'm fine posting my question. My job is to make a rude web browser. I have a textField in which the user enters the desired URL. Then I obviously have to go to this web page. Here is an example from my teacher about how my code would look something like this. This is the code I have to send to my socket. Example URL: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
GET /wiki/Hypertext_Transfer_Protocol HTTP/1.1\n Host: en.wikipedia.org\n \n
So my question is this: I'm going to read only one full line in the URL, so how do I extract only the part of "en.wikipedia.org" and only the extension? I tried this as a test:
String url = "http://en.wikipedia.org/wiki/Hypertext Transfer Protocol"; String done = " "; String[] hope = url.split(".org"); for ( int i = 0; i < hope.length; i++) { done = done + hope[i]; } System.out.println(done);
It just prints the URL without the ".org" in it. I think I'm on the right track. I'm just not sure. In addition, I know that websites can have different endings (.org, .com, .edu, etc.), so I assume that I will need several if statements that compensate for different possible endings. Basically, how do I get the URL in two parts that I need?
source share