I have to write a program that accepts a URL from the user and
splits it into its 3 major components.
For example:
If your string is:
http://www.cnn.com/~cse110
your output should be
Protocol : http
Address : www.cnn.com
Resource : ~cse110
Printable View
I have to write a program that accepts a URL from the user and
splits it into its 3 major components.
For example:
If your string is:
http://www.cnn.com/~cse110
your output should be
Protocol : http
Address : www.cnn.com
Resource : ~cse110
look up string Tokenizer
Well firstly StringTokenizer is deprecated so you shouldn't use that. You should use the split() method in the String class. It achieves pretty much the same result.
However, in this case you should look at the URL class. You can find information on it here. It parses URL's, and has methods for you to extract the information you need.
really? when did that happen?
well since its an intro class the instructor wants us to use tokenizer
Don't know when but I remember reading this about 6 months back at the API for StringTokenizer:
The split feature of String is pretty good. It puts all the "tokens" in an array of Strings. It also allows the use of regular expressions for splitting which makes it pretty powerful. I remember coding with Tokenizer was a big source of exceptions if I wasn't careful.Quote:
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.
be sure to tell your instructor that this is the nineties; tokenizer is dead, let's split..Quote:
Originally posted by Yankeez
well since its an intro class the instructor wants us to use tokenizer
speaking of which, you can find a tutorial in my sig
This is the nineties? Now I'm confused.Quote:
be sure to tell your instructor that this is the nineties; tokenizer is dead, let's split..