Learning F# while trying to do something useful at the same time, so this is kind of basic question:
I have req
, which is a HttpListenerRequest
, which has QueryString
property, with type System.Collections.Specialized.NameValueCollection
. So, for sake of clarity let's say, I have
let queryString = req.QueryString
Now I want to produce nice string (not printf to console) from contents of that, but queryString.ToString()
is not overriden apparently, so it just gives string "System.Collections.Specialized.NameValueCollection".
So, what's the F# one-liner to get a nice string out of that, like "key1=value1\nkey2=value2\n..."?
nvc.AllKeys
|> Seq.map (fun key -> sprintf "%s=%s" key nvc.[key])
|> String.concat "\n"
Something like this ought to work:
let nvcToString (nvc:System.Collections.Specialized.NameValueCollection) =
System.String.Join("\n",
seq { for key in nvc -> sprintf "%s=%s" key nvc.[key] })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With