Quote:
Originally Posted by Stang02GT
Hello,
I've been placed on a web analytics project to try and get so me Java experience/web development. I have very little Java knowledge, and hoping that you guys can help me out a little.
I have been asked to come up with a Java method that takes a URL string and alphabetizes the parameters. This is what i was given to start...
- int questionPos = inUrl.indexOf("?");
-
if (questionPos >= 0) {
-
StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
-
-
StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
-
-
while (tokenizer.hasMoreTokens()) {
-
String key = tokenizer.nextToken();
-
}
-
-
}
I have no idea what this does or even where to start. Any help/guidance would be great!
That code snippet tries to manipulate a URL: blablah?foo&bar&baz.
It stores the blahblah? part in a StringBuffer and scans for the substrings that
don't consist an ampersand '&'; in the example those are foo, bar and baz.
I'd use the
String.split() method if I were you,
kind regards,
Jos