challenge 条件を満たす行を取り除く

ファイルから1行ずつ読み込み、"#"で始まる行だけを取り除いてファイルに出力するコードを書いてください。

サンプル入力

hello!
# remove this
 # don't remove this
bye!
サンプル出力
hello!
 # don't remove this
bye!

Posted feedbacks - StandardML

手続き型で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
fun rm_comment_line (rf::wf::[]) =
  let
    open TextIO

    val r = openIn rf
    val w = openOut wf

    fun rm_comment_line' NONE = (closeIn r; closeOut w)
      | rm_comment_line' (SOME x) = (
      if String.isPrefix "#" x then () else output (w, x);
      rm_comment_line' (inputLine r)
      )
  in
    rm_comment_line' (inputLine r)
  end
  | rm_comment_line _ = ();

rm_comment_line (CommandLine.arguments ())

Index

Feed

Other

Link

Pathtraq

loading...