[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

vb.net - convert text file from unix to dos

Posted on 2011-09-21
3
Medium Priority
?
1,546 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 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