0
이것은 F # 용입니다.다른 행 값을 기반으로하는 F #의 행 값 추가
나는 4 행이있는 .data 파일이 있습니다. 마을, 인구, 자치 도시, 시골 또는 도시 유형의 마을. Int32.Parse를 사용하여 "population"열을 이미 파싱했습니다.
제 질문은, 자치 도시 이름을 기반으로하는 모든 행의 인구를 어떻게 추가 할 수 있습니까? 동일한 시정촌에 속해 있으며 같은 시정촌에있는 인구를 추가하려는 여러 도시가 있습니다.
이
내가 지금까지 어떤 도움이 감사 한 코드입니다 :open System
let rec convertDataRow(csvLine:string) =
let cells = List.ofSeq(csvLine.Split(','))
match cells with
| name :: popul :: county :: townorcommune :: _ ->
let parsedNumber = Int32.Parse(popul)
(name, parsedNumber, county, townorcommune)
| _ -> failwith "Incorrect data format!"
let rec processLines (lines) =
match lines with
| [] -> []
| currentLine :: remaining ->
let parsedLine = convertDataRow(currentLine)
let parsedRest = processLines(remaining)
parsedLine :: parsedRest
open System.IO
let lines = List.ofSeq(File.ReadAllLines(@"C:\Users\townspopulation.data"))
processLines(lines)
에게 합계 배,하지만 난 냄새 전에 숙제. – Daniel