Solved

vb.net - reading file

Posted on 2011-09-21
5
187 Views
Last Modified: 2012-08-13
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?
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

Open in new window

0
Comment
Question by:XK8ER
  • 2
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36577940
I think that you should be using the overloaded StreamReader constructor, with UTF encoding, instead of the default encoder.
0
 
LVL 1

Author Comment

by:XK8ER
ID: 36578222
how can I do that exactly?
0
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 36578474
Hi,

Change your line
Using inFile As New IO.StreamReader(strFilePath)
like below:
Using inFile As New IO.StreamReader(strFilePath, System.Text.Encoding.Default, False)

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 36578513
now

Copyright ©2000

becomes

Copyright ©2000
0
 
LVL 12

Accepted Solution

by:
rajapandian_81 earned 500 total points
ID: 36578549
ok..

Instead of System.Text.Encoding.Default, try System.Text.Encoding.UTF8.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question