Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing a empty line from a Text file 1

Status
Not open for further replies.

Howlingmad

IS-IT--Management
Dec 23, 2004
9
0
0
GB
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
 
Hello Howlingmad,

May be a bit shaky... try this?
[tt]
strText = objTextFile.ReadAll
strText = Replace(strText, "", "")
strText = Replace(strText, vbcrlf & vbcrlf, vbcrlf)
[/tt]
regards - tsuji
 
Further notes:

Maybe this is more correct?
[tt]
strText = objTextFile.ReadAll
strText = Replace(strText, "" & vbcrlf, "")
[/tt]
- tsuji
 
Thanks for replying tsuji, but this doesnt appear to work
 
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.
[tt] wscript.echo escape(strText)[/tt]
or if it is too big, write it out to some file. No need to speculate/imagine further.

- tsuji
 
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.
 
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

[blue]An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi[/blue]
 
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
 
Thanks very much Cornboy88 it worked Perfectly after i changed chr(127) to "
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top