VB Scripting help required
Discussion
Folks,
I need to tidy up a file..
I need to remove all blank spaces!
The file is a list of computer names, there are three leading blank lines, and many blank characters after each entry, there is only one entry per line..
So, I would like to be able to remove any blank "characters" (spaces) from the file..
Is there an easy way of doing this?
TIA,
slinky
587racing.com
I need to tidy up a file..
I need to remove all blank spaces!
The file is a list of computer names, there are three leading blank lines, and many blank characters after each entry, there is only one entry per line..
So, I would like to be able to remove any blank "characters" (spaces) from the file..
Is there an easy way of doing this?
TIA,
slinky
587racing.com
slinky said:
Folks,
I need to tidy up a file..
I need to remove all blank spaces!
The file is a list of computer names, there are three leading blank lines, and many blank characters after each entry, there is only one entry per line..
So, I would like to be able to remove any blank "characters" (spaces) from the file..
Is there an easy way of doing this?
TIA,
slinky
587racing.com
MS Excel, use the =TRIM() function.
This will remove spaces at either end but NOT in between.
If you have spaces in between it's a bit more complicated . .
Data text to columns the =CONCANTENATE()
Plotloss said:
You cant update a file with vbScript.
You can delete it and recreate it but there is no edit as such to maintain file system security.
So it would be a case of iteratively reading each text line, trimming the spaces out and writing that line to a new file.
Not strictly true.
Pseudo code would be
- Read file into memory
- process line by line using trim or ltrim, rtrim
- then write file back out when you're doing using option to overwrite original.
To give you a little more information, the file is a flat text file with no formatting.. (the output from a "DOS" command)... in order to pipe this data into another script I need to remove the leading spaces and non required data..
I only require the first word on each line (computer name)...
here's an example of some of the text..
ABETTERTON Anne Betterton
ACCSRV1
ACOUPLAND
AJMONAGHAN
So I need to remove anything after the first block of characters, on each line...
TIA,
slinky
I only require the first word on each line (computer name)...
here's an example of some of the text..
ABETTERTON Anne Betterton
ACCSRV1
ACOUPLAND
AJMONAGHAN
So I need to remove anything after the first block of characters, on each line...
TIA,
slinky
Think this would do what you need...
code said:
Dim strData() As String
Dim strTemp As String
Dim FF As Integer
Dim intPos As Integer
Dim intLoop As Integer
Dim intCount As Integer
FF = FreeFile
Open "C:Data.txt" For Input As #FF
intLoop = 0
While Not EOF(FF)
Line Input #FF, strTemp
If strTemp <> "" Then
intPos = InStr(1, strTemp, " ", vbTextCompare)
strTemp = Mid$(strTemp, 1, (intPos - 1))
ReDim Preserve strData(0 To intLoop)
strData(intLoop) = strTemp
intLoop = intLoop + 1
End If
Wend
Close #FF
Open "C:Data.txt" For Output As #FF
intLoop = UBound(strData())
For intCount = 0 To intLoop
Write #FF, strData(intCount)
Next intCount
Close #FF
Tis done..
Cheers for all of your input guys!
slinky
coding bloke in the office said:
Const ForReading = 1, ForWriting = 2
Dim fso,txtInputFile, txtOutPutFile
strInputFileName = "infile.txt"
strOutPutFileName = "PCRerun.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtInputFile = fso.OpenTextFile(strInputFileName)
Set txtOutPutFile = fso.createTextFile(strOutPutFileName)
Do While txtInputFile.AtEndOfStream <> True
txtReadLine = trim(txtInputFile.Readline)
if left(txtReadline, 2) = "\" then
myPos = Instr(1, txtReadLine, chr(32))
if myPos <> 0 then
txtReadLine = Left(txtReadLine, myPos-1)
end if
txtOutPutFile.WriteLine(txtReadLine)
end if
Loop
txtInputFile.Close
txtOutPutFile.Close
Cheers for all of your input guys!
slinky
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff






