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

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

サンプル入力

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

Posted feedbacks - Emacs Lisp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(defun remove-comments ()
  (goto-char (point-min))
  (while (re-search-forward "^#" nil t)
    (delete-region (point-at-bol) (1+ (point-at-eol)))))

(defun test ()
  (save-excursion
    (set-buffer (find-file-noselect "10.input"))
    (remove-comments)
    (write-file "10.output")))
(test)

Index

Feed

Other

Link

Pathtraq

loading...