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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Script, Odd Issue

Status
Not open for further replies.

Richtoss

IS-IT--Management
Oct 7, 2008
6
US
I am trying to use a script to remove the blank spaces from the right side of a line, for every line on the file. It sounds simple and should be, I think. I will post the code below. The problem is that if the file has like 1000 lines in it, it will work great for every line except the very first line. The very first line will remain in the file with the blank spaces, Why?
(See code below)

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ITI\I00test", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
strLine = Trim(strLine) & vbCrLf
strText = strText & strLine

Loop


objFile.Close

Set objFile = objFSO.OpenTextFile("C:\iti\I00test", ForWriting)
objFile.Write strText
objFile.Close

Thanks,,

Richtoss
 
>The very first line will remain in the file with the blank spaces, Why?
The only reason is that it contains not the ordinary space. You can echo out it like this.
[tt]
[blue]bfirstline=true[/blue]
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
[blue]if bfirstline then
wscript.echo escape(strLine)
bfirstline=false
end if[/blue]
'etc etc
Loop
[/tt]
You should see nothing like %20 at the end.
 
Or you could create a dummy line for the first line your program reads. Then you wouldn't have to modify the code at all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top