Skip to content

Instantly share code, notes, and snippets.

@pjb3
Created February 19, 2009 05:11
Show Gist options
  • Select an option

  • Save pjb3/66736 to your computer and use it in GitHub Desktop.

Select an option

Save pjb3/66736 to your computer and use it in GitHub Desktop.
; HTTP query string parser, Clojure
(defn parse-query-string
"Parses a querystring into a hash"
[qs]
(into {} (map #(vec (.split % "=")) (.split qs "&"))))
# HTTP query string parser, Ruby
def parse_query_string(qs)
qs.split('&').inject({}){|h,p| k,v = p.split('='); h[k] = v; h}
end
-module(query_string).
-export([parse/1]).
parse(String) ->
lists:map(fun(P) -> L = string:tokens(P, "="),
{lists:nth(1, L), lists:nth(2, L)} end,
string:tokens(String, "&")).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment