XK8ER
asked on
vb.net - reading file
Hello there,
I have this function to convert unix text files into windows dos text format.
everything works fine but the issue is that for example I have a text with this in it
|| # Copyright ©2000-2011
after conversion it becomes
|| # Copyright ¿2000-2011
how can I prevent stuff like these from happening?
I have this function to convert unix text files into windows dos text format.
everything works fine but the issue is that for example I have a text with this in it
|| # Copyright ©2000-2011
after conversion it becomes
|| # Copyright ¿2000-2011
how can I prevent stuff like these from happening?
Private Sub TextUnixToWin(ByVal strFilePath As String)
Try
Dim outFile As New List(Of String)
Using inFile As New IO.StreamReader(strFilePath)
Try
Dim buffer As String = String.Empty
Try
While Not inFile.EndOfStream
buffer = inFile.ReadLine()
outFile.Add(buffer)
End While
Catch ex As Exception
Debug.Print("Error performing conversion: {0}", ex.Message)
Debug.Print("Press any key to exit...{0}", vbCrLf)
End Try
Catch ex As Exception
Debug.Print("Could not open out file: {0}", ex.Message)
Debug.Print("Press any key to exit...{0}", vbCrLf)
End Try
End Using
If outFile.Count > 0 Then
IO.File.WriteAllLines(strFilePath, outFile)
Debug.Print("done! > " & strFilePath)
End If
Catch ex As Exception
Debug.Print("Could not open in file: {0}", ex.Message)
Debug.Print("Press any key to exit...{0}", vbCrLf)
End Try
End Sub
I think that you should be using the overloaded StreamReader constructor, with UTF encoding, instead of the default encoder.
ASKER
how can I do that exactly?
Hi,
Change your line
Using inFile As New IO.StreamReader(strFilePat h)
like below:
Change your line
Using inFile As New IO.StreamReader(strFilePat
like below:
Using inFile As New IO.StreamReader(strFilePath, System.Text.Encoding.Default, False)
ASKER
now
Copyright ©2000
becomes
Copyright ©2000
Copyright ©2000
becomes
Copyright ©2000
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.