[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.net - How to take a text file and delete the CRLFs in the file

Posted on 2005-05-17
5
Medium Priority
?
360 Views
Last Modified: 2010-04-17
Hello!

I am using VS.NET to create a small module program that needs to take a text file and delete all the CRLFs in the file.  VB.net is the language I'm using.  I've searched through the questions in EE and haven't really found anything that allows me to do this.

As well, I need to delete the first couple lines as well as the last couple lines of the text file.  I have everything built except the editing of the text file itself - I'm stumped on how to do this.  Again, this is a simple .txt file that I need to edit.  Thank you!
0
Comment
Question by:gderoeck
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:rsmithnt
ID: 14021292
Maybe try replacing the chr(13)  with a "".  You may have to read each line of the text file at a time.  

While looping through  each line you can also delete the first 2 and last 2 lines.
0
 
LVL 1

Author Comment

by:gderoeck
ID: 14021410
Can you post some code to show this?  I'm trying to do what you suggested, but not having much luck.
0
 
LVL 1

Accepted Solution

by:
rsmithnt earned 1200 total points
ID: 14021504
This will read in a file and save it to a temp file.  Where you read in teh line, you will replace the return character with nothing.

The return character can be masked as vblf, vbnewline or chr(13).  You can try removing all three.

Hope this helps

 Private Sub CreateTmpFile(ByVal FilePath As String, ByVal tmp_filename As String)
                '------------------------------------------------
                '   Declares Variables
                '------------------------------------------------
                Dim tmp_writer As StreamWriter
                Dim tmp_reader As StreamReader
               
                '------------------------------------------------
                '   Creates a New Temp File
                '------------------------------------------------
                If File.Exists(FilePath & "\" & tmp_filename & ".tmp") Then
                    File.Delete(FilePath & "\" & tmp_filename & ".tmp")
                End If
                tmp_writer = File.CreateText(FilePath & "\" & tmp_filename & ".tmp")

                '-------------------------------------------------
                '   Opens the TXT file to be read
                '-------------------------------------------------
                tmp_reader = New StreamReader(FilePath & "\" & Filename)

                '-------------------------------------------------
                '   Writes old file to the new file
                '-------------------------------------------------
                Do While tmp_reader.Peek() >= 0
                    tmp_writer.WriteLine(tmp_reader.ReadLine())
                Loop

                '-------------------------------------------------
                '   Cleans up Variables
                '-------------------------------------------------
                FilePath = Nothing
                tmp_filename = Nothing
                Filename = Nothing
               
                tmp_reader.Close()
                tmp_reader = Nothing

                tmp_writer.Close()
                tmp_writer = Nothing
            End Sub
0
 
LVL 1

Author Comment

by:gderoeck
ID: 14021743
Excellent!  Thank you!
0
 
LVL 1

Expert Comment

by:rsmithnt
ID: 14021843
Anytime.

I am glad i could help
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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

834 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