Skip to content

Instantly share code, notes, and snippets.

@xnnyygn
Created October 21, 2014 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnnyygn/6db1b573663de7a06a93 to your computer and use it in GitHub Desktop.
Save xnnyygn/6db1b573663de7a06a93 to your computer and use it in GitHub Desktop.
a simple java program to parse query string
public class ParseQueryString {
public static void main(String[] args) {
String queryString = "foo=a&bar=b";
for(String pair : queryString.split("&")) {
int index = pair.indexOf('=');
// -1 means not found
// 0 means at beginnging, e.g '=a'
if(index <=0) {
continue;
}
String key = pair.substring(0, index);
String value = pair.substring(index + 1);
System.out.println(key + " => " + value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment