我试图创建一段代码,但无法使其工作。我能想到的最简单的例子是解析一些CSV文件。 假设我们有一个CVS文件,但是数据是以某种层次结构组织的。就像这样:解析分层CSV的功能方法
Section1;
;Section1.1
;Section1.2
;Section1.3
Section2;
;Section2.1
;Section2.2
;Section2.3
;Section2.4
等
我这样做:
let input =
"a;
;a1
;a2
;a3
b;
;b1
;b2
;b3
;b4
;b5
c;
;c1"
let lines = input.Split('\n')
let data = lines |> Array.map (fun l -> l.Split(';'))
let sections =
data
|> Array.mapi (fun i l -> (i, l.[0]))
|> Array.filter (fun (i, s) -> s <> "")
和我
val sections : (int * string) [] = [|(0, "a"); (4, "b"); (10, "c")|]
现在我想创建行索引范围的列表对于每个部分,如下所示:
[|(1, 3, "a"); (5, 9, "b"); (11, 11, "c")|]
其中第一个数字是小节范围的开始线索引,第二个是结束线索引。我怎么做?我正在考虑使用折叠功能,但无法创建任何东西。
非常好!这就是我需要的。谢谢。 – Max 2010-02-26 00:40:10