今回のサンプルにはちょっと大きかった。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use text.csv) | |
(use gauche.charconv) | |
(let ((file-name "../../data/43kumamo/43kumamo.csv")) | |
(length | |
(call-with-input-file file-name | |
(cut port->list (make-csv-reader #\,) <>) | |
:encoding 'shift_jis))) | |
; -> 1874 | |
(let ((file-name "../../data/43kumamo/43kumamo.csv")) | |
(length | |
(call-with-input-file file-name | |
(lambda (in) | |
(port->list (make-csv-reader #\,) in)) | |
:encoding 'shift_jis))) | |
; -> 1874 | |
(let ((file-name "../../data/43kumamo/43kumamo.csv") | |
(reader (make-csv-reader #\,))) | |
(length | |
(call-with-input-file file-name | |
(lambda (in) | |
(port->list reader in)) :encoding 'shift_jis))) | |
; -> 1874 | |
(let ((file-name "../../data/43kumamo/43kumamo.csv") | |
(reader (make-csv-reader #\,))) | |
(let/cc skip | |
(call-with-input-file file-name | |
(lambda (in) | |
(port-for-each (lambda (fields) | |
(skip fields)) | |
(lambda () | |
(reader in)))) :encoding 'shift_jis))) | |
; -> ("43201" "862 " "8610000" "クマモトケン" "クマモトシ" "イカニケイサイガナイバアイ" "熊本県" "熊本市" "以下に掲載がない場合" "0" "0" "0" "0" "0" "0") | |
(call-with-input-string "\"aaa\",\"b | |
bb\",\"ccc\",zzz,\"y\"\"Y\"\"y\",xxx" (make-csv-reader #\,)) | |
; -> ("aaa" "b\nbb" "ccc" "zzz" "y\"Y\"y" "xxx") |
参考
- Gauche ユーザリファレンス: 6.19 入出力
- Gauche ユーザリファレンス: 9.2 gauche.charconv - 文字コード変換
- Scheme:テキスト処理
- DouKaku? 4628 shiro: Gaucheでは、「shift jisで...(文字コードの変換) - Comment detail
- RFC 4180対応版 CSVレコードの分解 DouKaku?
- Gauche で CSV 形式のデータを読み込む : Serendip - Webデザイン・プログラミング
- Karetta|[Gauche] CSV出力
- CSVファイルを読む - Gaucheクックブック
今更ながら、どう書く?orgすげーな。shiroさんのコードがあるある。
0 件のコメント:
コメントを投稿