Solved How to strip spaces from delimited substrings in file

August 19, 2012 at 08:43:47
Specs: Windows Vista
I have a vbscript that will strip spaces from a file of un delimited strings. Can anyone help me to amend the script to remove spaces from right side of delimited text strings only, character count for each text string is fixed to 16 characters
eg file
"1" "3" "1001" "text + spaces " "more spaces "
"1" "3" "1002" "text + spaces " "more spaces "
"1" "3" "1003" "text + spaces " "more spaces
need to get file as follows
"1" "3" "1001" "text + spaces" "more spaces"
"1" "3" "1002" "text + spaces" "more spaces"
"1" "3" "1003" "text + spaces" "more spaces"
Script
strFileName="test.txt"
Set objFS = CreateObject("Scripting.FileSystemObject")
StrContents = Split(objFS.OpenTextFile(strFileName).ReadAll, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, 2)
For Each strLine In StrContents
objTS.WriteLine (Trim(strLine))
Next
Any help would be greatly appreciated

See More: How to strip spaces from delimited substrings in file

Report •


#1
August 19, 2012 at 09:58:18
✔ Best Answer
For anybody interested the following script fixes the problem..Enjoy!


Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\temp\Test.txt", ForReading)

strSearchString = objFile.ReadAll
objFile.Close

Set objRegEx = CreateObject("VBScript.RegExp")

objRegEx.Global = True
objRegEx.Pattern = " {2,}"

strSearchString = objRegEx.Replace(strSearchString, "")

Set objFile = objFSO.OpenTextFile("C:\temp\Test.txt", ForWriting)
objFile.WriteLine strSearchString

objFile.Close


Report •
Related Solutions


Ask Question