?
Solved

vb.net - reading file

Posted on 2011-09-21
5
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 36578549
ok..

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

718 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