Created
October 21, 2014 07:10
-
-
Save xnnyygn/6db1b573663de7a06a93 to your computer and use it in GitHub Desktop.
a simple java program to parse query string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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