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

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

サンプル入力

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

Posted feedbacks - Smalltalk

Squeak Smalltalk で手続き的に。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
| file out |
file := FileStream fileNamed: 'test.txt'.
out := FileStream newFileNamed: 'out.txt'.
[file atEnd] whileFalse: [
   | line |
   line := file nextLine.
   line first == $# ifFalse: [
      out nextPutAll: line.
      file peekLast == Character cr ifTrue: [out cr]]].
file close.
out edit

Index

Feed

Other

Link

Pathtraq

loading...