WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Remove Leading Zeros



;Put inputfilename into a variable
infile="infile.txt"
;put outputfilename ito a variable
outfile="outfile.txt"


;create a special string unlikely to ever appear in inoput data
;as a placeholder
special=StrCat(Num2Char(255),Num2Char(253))

;load entire input file into a variable
origdata=FileGet(infile)

; so the idea is to remove leading zeros from numbers EXCEPT
; for floating point numbers less than 1 like 0.12 which should retain
; the single leading zero

; so to protext the floating point numbers less than one, change "0." to the
; "special" string.
origdata=StrReplace(origdata,"0.",special)

; now we will assume the first number on the line NEVER needs to 
; have leading zeros removed.  So now we change any instance of
; space-0 to space-space, removing one leading zero for any number
;that has a leading zero
data=StrReplace(origdata," 0","  ")


; but wait... there may be more than one leading zero
; this lop continues to remove leading zeros till none are left
While  origdata != data
   origdata=data
   data=StrReplace(origdata," 0","  ")
EndWhile
;but how does it know when to stop?  By moving the data between
;the "origdata" and "data" variables..it checks to see when the
;variable do not chage after a strreplae.  That means there is no
;more stuff to change.  So the look looks to see when the data
; has stopped changing



;now to fix the floating point numbers, change the "special" string
; back to the 0. 
data=StrReplace(data,special,"0.")

;save the info to the output file
FilePut(outfile,data)

;tell user job is done
Message("All","Done")

Article ID:   W16700
File Created: 2005:02:18:12:21:54
Last Updated: 2005:02:18:12:21:54