Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best way to strip out trailing blanks/CR/LFs from a stri
Message
From
19/07/2004 13:29:40
 
 
To
19/07/2004 13:11:51
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00925773
Message ID:
00925846
Views:
25
>Sorry Fernando. Mike's and Alan's need to be reviewed.

Thanks for pointing my error, Gregory. I reviewed and here are the new results:
cTempSource= "        Test     of   " + chr(13) + Chr (10) + ;
             "      char   removal  " + chr(13) + Chr (10) + ;
                                        chr(13) + Chr (10) + ;
             Space ( 5)               + chr(13) + Chr (10) + ;
             Space (10)

* Gregory Adam (StripTrailing)

cSourceString = cTempSource

t1= Seconds ()
 
For I = 1 To 100000
    cRem = left(cSourceString, len (rtrim (strtran (strtran(cSourceString, chr(10), ' ') , chr(13), ' '))))
EndFor

Elap1 = Seconds () - t1

* Gregory Adam (StripTrailing2)

cSourceString = cTempSource

t1= Seconds ()

For I = 1 To 100000
    cRem = left(cSourceString, len (rtrim (chrtran (cSourceString, chr(10) + chr(13), '  '))))
EndFor

Elap2 = Seconds () - t1

* Fabio Lunardon

cSourceString = cTempSource

t1= Seconds ()

c= Space (1) + chr(13) + Chr (10)
	
For I = 1 To 100000
    cRem = Left (cSourceString, Len (rTrim (ChrTran (cSourceString, c, Space (Len (c))))))
EndFor

Elap3 = Seconds () - t1

* Alan Popow

t1= Seconds ()

For I = 1 To 100000

    cSourceString = cTempSource   &&  Modified

    Do While Right (cSourceString, 1) $ (" " + Chr (13) + Chr (10))
       cSourceString = Left (cSourceString, Len (cSourceString) - 1)
    EndDo
EndFor

Elap4 = Seconds () - t1

* Mike Pratt 

t1= Seconds ()

For I = 1 To 100000

    cSourceString = cTempSource   &&  Modified

    Do While InList (Right (cSourceString, 1), Chr (32), Chr (10), Chr (13))
	   cSourceString = Left (cSourceString, Len (cSourceString) - 1)
    EndDo
EndFor

Elap5 = Seconds () - t1

* Steve Gibson 

cSourceString = cTempSource

t1= Seconds ()

For I = 1 To 100000
	* trim leading & trailing CR,LF,spaces, and tabs
	lcCharsToTrim = chr(13) + chr(10) + ' ' + chr(9)

	lcOutString = allTrim(cSourceString)

	* trim trailing items
	lnLength = len(lcOutString)
	lnTrim = 0
	do while substr(lcOutString,lnLength - lnTrim, 1) $ lcCharsToTrim
		lnTrim = lnTrim + 1
	enddo
	if lnTrim > 0
		lcOutString = substr(lcOutString,1,lnLength - lnTrim)
	endif

	* trim leading items
	lnTrim = 0	
	do while substr(lcOutString, lnTrim + 1, 1)	$ lcCharsToTrim
		lnTrim = lnTrim + 1
	enddo
	if lnTrim > 0
		lcOutString = substr(lcOutString,lnTrim+1,lnLength - lnTrim)
	endif
EndFor

Elap6 = Seconds () - t1

MessageBox ("Gregory Adam (StripTrailing):  " + Transform (Elap1) + Chr (13) + Chr (10) + ;
            "Gregory Adam (StripTrailing2): " + Transform (Elap2) + Chr (13) + Chr (10) + ;
            "Fabio Lunardon: "                + Transform (Elap3) + Chr (13) + Chr (10) + ;
            "Alan Popow: "                    + Transform (Elap4) + Chr (13) + Chr (10) + ;
            "Mike Pratt: "                    + Transform (Elap5) + Chr (13) + Chr (10) + ;
            "Steve Gibson: "                  + Transform (Elap6) )
*
*After 100,000 loops for each routine I got the following results:
*Gregory Adam (StripTrailing):  0.875
*Gregory Adam (StripTrailing2): 0.187
*Fabio Lunardon:                0.203
*Alan Popow:                    3.938
*Mike Pratt:                    3.953
*Steve Gibson:                  2.015
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform