条件を満たす行を取り除く
Posted feedbacks - VB.net
1行ずつ読み込みということなのでReadLineを使用してます。ただ、まとめて読み込んでも短くはならないと思うけど。 Usingステートメントも使用できるけど、例外処理いれることを考えたらTryだけ使うほうがいいよね?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | Public Sub FilterFile(ByVal input As String, ByVal output As String)
Dim sr As StreamReader = Nothing
Dim sw As StreamWriter = Nothing
Try
sr = New StreamReader(input)
sw = New StreamWriter(output)
Do While sr.Peek <> -1
Dim line As String = sr.ReadLine
If Not line.StartsWith("#") Then
sw.WriteLine(line)
End If
Loop
Catch ex As Exception
Finally
If Not sr Is Nothing Then
sr.Close()
End If
If Not sw Is Nothing Then
sw.Close()
End If
End Try
End Sub
|


にしお
#3366()
Rating0/0=0.00
サンプル入力
サンプル出力[ reply ]