Solved

vb.net - reading file

Posted on 2011-09-21
5
186 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
Comment Utility
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
Comment Utility
how can I do that exactly?
0
 
LVL 12

Expert Comment

by:rajapandian_81
Comment Utility
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
Comment Utility
now

Copyright ©2000

becomes

Copyright ©2000
0
 
LVL 12

Accepted Solution

by:
rajapandian_81 earned 500 total points
Comment Utility
ok..

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now