首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

把合拢成字符串

2012-08-22 
把合并成字符串把合并成字符串let a1 seq [aabb]let a2 seq [aa]let a3 Seq.emptyredu

把合并成字符串
把合并成字符串

let a1 = seq ["aa";"bb"];;
let a2 = seq ["aa"];;
let a3 = Seq.empty;;

    reduce 对于空序列就不容易处理了。

let b1 = a1 |> Seq.reduce(fun a b -> a + "," + b);;
let b2 = a2 |> Seq.reduce(fun a b -> a + "," + b);;
let b3 = if (not ( Seq.isEmpty a3)) then
           Seq.reduce(fun a b -> a + "," + b) a3
         else
           ""   ;;  

    用 String.concat 就非常直观了、方便了。

let c1 = a1 |> String.concat(",");;
let c2 = a2 |> String.concat(",");;
let c3 = a3 |> String.concat(",");;

热点排行