?
Solved

Trimming spaces from file - VBS

Posted on 2006-05-14
1
Medium Priority
?
383 Views
Last Modified: 2008-03-06
NEED TO TRIM SPACES AFTER THE STREET ADDRESS, CITY, AND ZIP CODE.  SEE CODE BELOW

SOURCE FILE:
"Allen Bran ","45 STANLEY AVE ","CITY ","ST","55555 ","555555555","$9.95"
"Richard Puckt ","1606 S 21ST ST ","CITY ","ST","55555 ","5555555555","$9.95"

OUTPUT FILE:
A,-V-RX-NU-NG-M-H-FO-EP-CE-C-,,Allen,Bran,,45 STANLEY AVE ,,CITY ,ST,55555 ,,,4139,,,,5555555555
A,-V-RX-NU-NG-M-H-FO-EP-CE-C-,,Richard,Puckt,,1606 S 21ST ST ,,CITY ,ST,55555 ,,,4139,,,,5555555555

CODE:
Option Explicit

Const ForReading = 1

Dim objFSO
Dim objTextFile
Dim strOutputFile
Dim objOutputFile
Dim strL
Dim strOut
Dim arrR, arrR2
Dim strDate
Dim i, k

strDate = PadL(Month(Date()),2) & PadL(Day(Date()),2) & Year(Date())

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Projects\Processing\SJ\ucs" & strDate & ".txt", ForReading)
strOutputFile="C:\Projects\Processing\NewBen\Out\UCS-0"+Replace(FormatDateTime(Date()),"/","")+".txt"    ' current date, replacing forward slashes with dashes..
Set objOutputFile = objFSO.CreateTextFile(strOutputFile)

Do While not objTextFile.AtEndOfStream
    strL=objtextFile.Readline
    arrR=split(strL,",")
    for k=0 to 6
         arrR(k)=(replace(arrR(k),chr(34),"")
         
      next

    arrR(6)=empty   ' the $ amount, set to empty so it'll be ignored by the Join
    arrR2 = Split(arrR(0)," ")
   
    arrR(0) = "A,-V-RX-NU-NG-M-H-FO-EP-CE-C-,," & arrR2(0) & "," & arrR2(1) & ","
    arrR(1) =  arrR(1) & ","
    arrR(5) = ",,4139,,,," & arrR(5)
    strOut=Join(arrR,",")

    objOutputFile.Write left(strOut,len(strOut)-1) & vbCRLF  ' take off the extraneous comma added by the Join and add a CR + LF
Loop

objTextFile.close
objOutputFile.Close
SET objFSO=nothing

Function PadL(strText,nLength)
Dim strTemp
   strTemp = Space(nLength)
   strTemp = Replace(strTemp," ","0")
   PadL    = Right(strTemp & strText, nLength)
End Function
0
Comment
Question by:Webcc
1 Comment
 
LVL 97

Accepted Solution

by:
Lee W, MVP earned 1000 total points
ID: 16677949
Use Trim -

arrR(0) = "A,-V-RX-NU-NG-M-H-FO-EP-CE-C-,," & Trim(arrR2(0)) & "," & Trim(arrR2(1)) & ","
arrR(1) =  Trim(arrR(1)) & ","
arrR(5) = ",,4139,,,," & Trim(arrR(5))
strOut=Join(arrR,",")

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question