INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Removing a empty line from a Text file

Share

Removing a empty line from a Text file

Removing a empty line from a Text file

(OP)
Can some one help me?  Im using VBscript to remove a Character from a Text file (see below script).  The problem i have is that when the character is removed the line it was on remains, which mean there is a gap in the text.  Is there anyway i can remove then empty line?

Const ForReading = 1
Const ForWritting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("C:\Tolisbon\output.txt")

Set objTextFile = objFSO.OpenTextFile("c:\emigrants\btd04.dat", ForReading)

strText = objTextFile.ReadAll
strText = Replace(strText, "", "")
objTextFile.Close
objOutputFile.WriteLine strText

Set objTextFile = objFSO.OpenTextFile("C:\Tolisbon\btd04.txt ", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText

objOutputFile.Close

RE: Removing a empty line from a Text file

Hello Howlingmad,

May be a bit shaky... try this?

strText = objTextFile.ReadAll
strText = Replace(strText, "", "")
strText = Replace(strText, vbcrlf & vbcrlf, vbcrlf)

regards - tsuji

RE: Removing a empty line from a Text file

Further notes:

Maybe this is more correct?

strText = objTextFile.ReadAll
strText = Replace(strText, "" & vbcrlf, "")

- tsuji

RE: Removing a empty line from a Text file

(OP)
Thanks for replying tsuji, but this doesnt appear to work

RE: Removing a empty line from a Text file

howlingmad,

First, why the character appear at all? Is it due to wrong setting of opentextfile with default format ascii on a unicode text file?

Second, linefeed and carriage-return may not always be use as vbcrlf, may well be vblf, or vblf & vbcr or whatever...

So to see what's going on, display the whole .readall in escaped form. Then, you can read out what's happening.
    wscript.echo escape(strText)
or if it is too big, write it out to some file. No need to speculate/imagine further.

- tsuji

RE: Removing a empty line from a Text file

(OP)
The character is a stop character for a BAC's file.  If a file wasnt sent the day before i need the program to combine the two files remove the stop character.  Which what i got at the moment does.  It just leaves that pesky empty line which means the file isnt read properly.

RE: Removing a empty line from a Text file

Hi Howlingmad,

the box character only says: cannot display this. You cannot search for it like that.
You need to replace the respective ASCii value. I suggest, you open the file in an editor with hex view and find out the character value. Then:

strText = objTextFile.ReadAll
strText = Replace(strText, chr(whatevercode) & vbcrlf, "")

Hope this helps.

Regards,
Andy

An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi

RE: Removing a empty line from a Text file

try this:

CODE

Const ForReading = 1
Const ForWritting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("C:\Tolisbon\output.txt")

Set objTextFile = objFSO.OpenTextFile("c:\emigrants\btd04.dat", ForReading)


Do While objTextFile.AtEndOfStream <> True
    strText = objTextFile.ReadLine
          if strText = chr(127) then
    else
        objOutputFile.WriteLine strText
    end if
    
   Loop

objTextFile.Close

Set objTextFile = objFSO.OpenTextFile("C:\Tolisbon\btd04.txt ", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText

objOutputFile.Close

RE: Removing a empty line from a Text file

(OP)
Thanks very much Cornboy88 it worked Perfectly after i changed chr(127) to ""

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close