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

For anybody interested the following script fixes the problem..Enjoy!

Const ForReading = 1

Const ForWriting = 2Set objFSO = CreateObject("Scripting.FileSystemObject")

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

objFile.CloseSet 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 strSearchStringobjFile.Close

Ask Your Question

Weekly Poll

Did you buy anything on Amazon's Prime Day?

Discuss in The Lounge

Poll History