?
Solved

vb.net - convert text file from unix to dos

Posted on 2011-09-21
3
Medium Priority
?
1,511 Views
Last Modified: 2012-05-12
hello there,
I have a little app that can convert a text file from unix into windows dos..
http://www.thefreecountry.com/tofrodos/index.shtml
I would like to know how can I do the same thing with vb.net
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
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36576106
How are you loading and reading the unix file?
0
 
LVL 1

Author Comment

by:XK8ER
ID: 36576114
well i dont know how to load it or read it since I think its a different approach here
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 2000 total points
ID: 36576193
As I understand it, the only difference between a Unix file and a Windows file is that Unix uses a newline character as a line-ending, whereas Windows uses a carriage return/newline pair (assuming you're talking about text files).

Since StreamReader.ReadLine will read up to the next line ending (whether it's a linefeed, carriage return, or carriage return/linefeed pair), and return the text without the line ending - and StreamWriter.Write will automatically append whatever line ending is defined in Environment.NewLine (which is always a carriage return/linefeed pair on Windows), you should be able to just open the file, StreamReader.Read a line, StreamWriter.Write the line to the output file and repeat until you reach the end of input.

Imports System.IO
Imports System.Text

Module Module1

    Sub Main(ByVal commandLineArgs() As String)

        If commandLineArgs.Length <> 2 Then
            Console.WriteLine("Usage:")
            Console.WriteLine("{0}{1} <in file> <out file>", vbTab, Reflection.Assembly.GetExecutingAssembly().Location)
            Console.WriteLine("{0}Press any key to exit...{1}", vbTab, vbCrLf)
            Console.ReadKey()
            Environment.Exit(1)
        End If

        Try
            Using inFile As New StreamReader(commandLineArgs(0))
                Try
                    Using outFile As New StreamWriter(File.Open(commandLineArgs(1), FileMode.CreateNew))
                        Dim buffer As String = String.Empty
                        Try
                            While Not inFile.EndOfStream
                                buffer = inFile.ReadLine()
                                outFile.WriteLine(buffer)
                            End While
                            Environment.Exit(0)
                        Catch ex As Exception
                            Console.WriteLine("Error performing conversion: {0}", ex.Message)
                            Console.WriteLine("Press any key to exit...{0}", vbCrLf)
                            Console.ReadKey()
                            Environment.Exit(4)
                        End Try
                        
                    End Using
                Catch ex As Exception
                    Console.WriteLine("Could not open out file: {0}", ex.Message)
                    Console.WriteLine("Press any key to exit...{0}", vbCrLf)
                    Console.ReadKey()
                    Environment.Exit(3)
                End Try
            End Using
        Catch ex As Exception
            Console.WriteLine("Could not open in file: {0}", ex.Message)
            Console.WriteLine("Press any key to exit...{0}", vbCrLf)
            Console.ReadKey()
            Environment.Exit(2)
        End Try
    End Sub

End Module

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 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