CLEAR
SET TALK OFF
SET SAFETY OFF
*===================================================
[b][COLOR=red]This is my corrected code, row-wise,
with no $ operator and minimum possible macro substitutions:[/color][/b]
*===================================================
a=SECONDS()
SELECT Double_Space_1
nFld=AFIELDS(aFld)
SCAN
FOR i=1 to nFld
fld2chk=aFld(i,1)
fldVal=EVALUATE(aFld(i,1))
IF aFld(i,2)="C" AND AT(' ',ALLTRIM(fldVal))>0
DO WHILE AT(' ',ALLTRIM(fldVal))>0
fldVal=STRTRAN(fldVal,' ',' ')
ENDDO
REPLACE &fld2chk WITH fldVal
ENDIF
ENDFOR
ENDSCAN
b=SECONDS()
?b-a [COLOR=navy grey]&& Average running time [b]194.1095[/b] seconds[/color]
*===================================================
[b][COLOR=red]This my code, also row-wise but using $ operator
and macro substitutions, and also performing REPLACE within DO WHILE loop:[/color][/b]
*===================================================
a=SECONDS()
SELECT Double_Space_2
nFld=AFIELDS(aFld)
SCAN
FOR i=1 to nFld
fld2chk=aFld(i,1)
IF aFld(i,2)="C" AND ' '$ALLTRIM(&fld2chk)
DO WHILE ' '$ALLTRIM(&fld2chk)
REPLACE &fld2chk WITH STRTRAN(&fld2chk,' ',' ')
ENDDO
ENDIF
ENDFOR
ENDSCAN
b=SECONDS()
?b-a [COLOR=navy grey]&& Average running time [b]443.1205[/b] seconds[/color]
*===================================================
[b][COLOR=red]This is [u]TheRambler[/u]’s unchanged code, also row-wise:[/color][/b]
*===================================================
a=SECONDS()
SELECT Double_Space_3
COPY STRUCTURE EXTENDED TO temp
SELECT field_name ;
FROM temp ;
WHERE field_type="C" ;
INTO ARRAY aFldCnt
SELECT Double_Space_3
howMany = alen(aFldCnt)
SCAN
FOR i=1 to howMany
fldVal = ALLTRIM(EVALUATE(aFldCnt(i)))
IF " "$fldVal
DO WHILE ' '$fldVal
fldVal=STRTRAN(fldVal,' ',' ')
ENDDO
REPLACE &aFldCnt(i) WITH fldVal
ENDIF
ENDFOR
ENDSCAN
b=SECONDS()
?b-a [COLOR=navy grey]&& Average running time [b]202.4060[/b] seconds[/color]
*===================================================
[b][COLOR=red]This is [u]mcamardo[/u]’s own code, column-wise
and performing REPLACE within DO WHILE loop:[/color][/b]
*===================================================
a=SECONDS()
SELECT Double_space_4
Dimension Afld(Fcount())
Store 0 To cntr2
For cntr1 = 1 To Fcount()
If Type(Field(cntr1)) = 'C'
cntr2 = cntr2 + 1
Store Field(cntr1) To Afld(cntr2)
Endif
Next cntr1
Arycnt = cntr2
For cntr3 = 1 To Arycnt
Store Afld(cntr3) To fld2chk
Scan for ' '$allt(&fld2chk)
Do While ' '$allt(&fld2chk)
Repl &fld2chk With Strt(Allt(&fld2chk), ' ', ' ')
Enddo
Endscan
Next cntr3
b=SECONDS()
?b-a [COLOR=navy grey]&& Average running time [b]335.3145[/b] seconds[/color]
*===================================================
SET TALK ON