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

Keep leading spaces on a string (readline method)

Status
Not open for further replies.

sfn6

Programmer
Aug 30, 2001
11
US
Hello all.

I'm writing a script to add some lines to about 1200 text files.

The script is done with one problem. I need to preserve the formatting in the orignial text files while adding the lines I need to add.

The original file is formatted with spaces, either 2, 4, 6 or 8 spaces before the first actual character in the line. I need to preserve this as I'm writing it out to a new file with the corrections.

The script works except for keeping the formatting, all leading spaces are removed. When I insert the 9 lines I need to add, I'm using space(n) to add the lines. How the heck do I keep the leading spaces in the stuff I read in? (readline)
 
I'll leave the original message up as a monument to stupidity.

I was trimming the damn spaces myself earlier in the code....
 
I have never seen this problem. Could you post your code? As a test, I used a text file that contained:
Code:
        This line has 8 leading spaces
    This has 4
This has 0

Used this code:
Code:
Option Explicit

Dim oFSO:Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim oFile
Dim oNewFile

Set oFile = oFSO.OpenTextFile("Test.txt")
Set oNewFile = oFSO.CreateTextFile("Test2.txt", True)

Do While Not oFile.AtEndOfStream
	oNewFile.WriteLine oFile.ReadLine()
Loop

oNewFile.WriteLine "This line was added with 0 spaces"
oNewFile.WriteLine Space(4) & "This line was added with 4 spaces"
oNewFile.WriteLine Space(8) & "This line was added with 8 spaces"

oFile.Close
oNewFile.Close
Set oNewFile = Nothing
Set oFile = Nothing
Set oFSO = Nothing

and the resulting file looked like this:
Code:
        This line has 8 leading spaces
    This has 4
This has 0
This line was added with 0 spaces
    This line was added with 4 spaces
        This line was added with 8 spaces

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
In that case, never mind. :)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top