问题描述
学习F#,同时试图做一些事情,同时是有用的,所以这是一种基本的问题:
我有 REQ
,这是一个 HttpListenerRequest
,其中有查询字符串
属性中,键入 System.Collections.Specialized.NameValueCollection
。因此,为了清楚起见,让我们说,我有
让QUERYSTRING = req.QueryString
现在我想产生很好的字符串(不printf的安慰),从该内容,但 queryString.ToString()
显然不是重写,所以它只是给串System.Collections.Specialized.NameValueCollection。
那么,什么是F#一行程序得到一个不错的串出,像键1 =值\ nkey2 =值2 \ñ......?
nvc.AllKeys
|> Seq.map(FUN键 - >的sprintf%s =%S键雷士照明[关键])
|> String.concat\ N
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"
这篇关于F#基础:转动的NameValueCollection成漂亮的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!