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:11:51
 
 
To
19/07/2004 13:03:33
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00925773
Message ID:
00925840
Views:
27
Sorry Fernando. Mike's and Alan's need to be reviewed.

The conclusion is: avoid loops

cheers,

Gregory
_______________________
Gregory,
>
>Meanwhile you where posting your last message I was trying to update mine with a correction.
>
>As I didn't reinitialize the search string (cSourceString) before each new loop, it altered the results, because when another routine would be performed it got cSourceString already without the Spaces/CRs/LFs.
>
>Below is the new sequence, and results:
>
>* Gregory Adam (StripTrailing)
>
>cSourceString= "        Test     of   " + chr(13) + Chr (10) + ;
>               "      char   removal  " + chr(13) + Chr (10) + ;
>                                          chr(13) + Chr (10) + ;
>               Space ( 5)               + chr(13) + Chr (10) + ;
>               Space (10)
>
>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= "        Test     of   " + chr(13) + Chr (10) + ;
>               "      char   removal  " + chr(13) + Chr (10) + ;
>                                          chr(13) + Chr (10) + ;
>               Space ( 5)               + chr(13) + Chr (10) + ;
>               Space (10)
>
>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= "        Test     of   " + chr(13) + Chr (10) + ;
>               "      char   removal  " + chr(13) + Chr (10) + ;
>                                          chr(13) + Chr (10) + ;
>               Space ( 5)               + chr(13) + Chr (10) + ;
>               Space (10)
>
>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
>
>cSourceString= "        Test     of   " + chr(13) + Chr (10) + ;
>               "      char   removal  " + chr(13) + Chr (10) + ;
>                                          chr(13) + Chr (10) + ;
>               Space ( 5)               + chr(13) + Chr (10) + ;
>               Space (10)
>
>t1= Seconds ()
>
>For I = 1 To 100000
>    Do While Right (cSourceString, 1) $ (" " + Chr (13) + Chr (10))
>       cSourceString = Left (cSourceString, Len (cSourceString) -1)
>    EndDo
>EndFor
>
>Elap4 = Seconds () - t1
>
>* Mike Pratt
>
>cSourceString= "        Test     of   " + chr(13) + Chr (10) + ;
>               "      char   removal  " + chr(13) + Chr (10) + ;
>                                          chr(13) + Chr (10) + ;
>               Space ( 5)               + chr(13) + Chr (10) + ;
>               Space (10)
>
>t1= Seconds ()
>
>For I = 1 To 100000
>    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= "        Test     of   " + chr(13) + Chr (10) + ;
>               "      char   removal  " + chr(13) + Chr (10) + ;
>                                          chr(13) + Chr (10) + ;
>               Space ( 5)               + chr(13) + Chr (10) + ;
>               Space (10)
>
>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.765
>Gregory Adam (StripTrailing2): 0.188
>Fabio Lunardon:                0.203
>Alan Popow:                    0.094
>Mike Pratt:                    0.093
>Steve Gibson:                  2.047
>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform