Guide Contents
|
DigitalDan Home Page
|
Private Shared Function ReadFile(fileName as string) as List(Of String)
Dim ret As New List(of String): ret.Clear
Dim linein As String
Dim errorMessage As String
Try
Using sr1 As New IO.StreamReader(fileName)
While Not sr1.EndOfStream
linein = sr1.ReadLine
' Processes line of text held in linein
ret.Add(linein)
End While
End Using
Catch ex as Exception
errorMessage = Ex.Message
End Try
Return ret
End Function
Private Shared Function ReadFile(fileName as string) as String
Dim allIn As String = String.Empty
Dim errorMessage As String
Try
Using sr1 As New IO.StreamReader(fileName)
allIn = sr1.ReadToEnd()
End Using
Catch ex as Exception
errorMessage = Ex.Message
End Try
Return allIn
End Function
Private Shared Function ReadFile(fileName as string) as String()
Dim ret As String() = Array.Empty(Of String)
Dim errorMessage As String
Try
Using sr1 As New IO.StreamReader(fileName)
ret = sr1.ReadToEnd().Split(vbcrlf)
End Using
Catch ex as Exception
errorMessage = Ex.Message
End Try
Return ret
End Function
Private Shared Function WriteFile(fileName As String, lines() As String) As String
Dim errorMessage As String = String.Empty
Try
Using sw1 As New IO.StreamWriter(fileName)
For Each s As String In lines
sw1.WriteLine(s)
Next
End Using
Catch ex As Exception
errorMessage = ex.Message
End Try
Return errorMessage
End Function
Private Shared Function WriteFile(fileName As String, lines() As String) As String
Dim errorMessage As String = String.Empty
Try
Using sw1 As New IO.StreamWriter(fileName)
For i As Integer = 0 To lines.Length - 1
If i < lines.Length - 1 Then
sw1.WriteLine(lines(i))
Else
sw1.WriteLine(lines(i))
End If
Next
End Using
Catch ex As Exception
errorMessage = ex.Message
End Try
Return errorMessage
End Function
Private Shared Function WriteFile(filename As String, lines() As String) As String
Dim errorMessage As String = String.Empty
Try
Using sw1 As New IO.StreamWriter(filename)
sw1.Write(String.Join(vbCrLf, lines))
End Using
Catch ex As Exception
errorMessage = ex.Message
End Try
Return errorMessage
End Function