>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) > >* Gregory Adam (StripTrailing) > >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) > >t1= Seconds () > >For I = 1 To 100000 > cRem = left(cSourceString, len (rtrim (chrtran (cSourceString, chr(10) + chr(13), ' ')))) >EndFor > >Elap2 = Seconds () - t1 > >* Fabio Lunardon > >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 > 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 > 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 > >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 (P4 2.4ghz, 512mb, Win XP, VFP 8):
>Gregory Adam (StripTrailing): 0.797 >Gregory Adam (StripTrailing2): 0.172 >Fabio Lunardon: 0.203 >Alan Popow: 0.094 >Mike Pratt: 0.109 >Steve Gibson: 0.438 >>Thanks so much, fellows, for your kind contribution!