Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove excessive spaces in string
Message
De
25/07/2009 13:53:13
 
 
À
24/07/2009 20:14:42
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01414370
Message ID:
01414494
Vues:
65
>When introducing the support for multiple passes, I neglected to reset the test string value to the original value for the Reduce_Successive and Reduce_Loop functions, making them look a lot better than they actually are.
>
>Fixed code:
>
>CLEAR
>
>SET TALK OFF
>SET DECIMALS TO 3
>
>SET LIBRARY TO ( HOME( ) + "FoxTools.FLL" ) ADDITIVE
>
>LOCAL ;
>	lnPasses
>
>lnPasses = 100
>
>=RunTest( "2", lnPasses ) && 2^2 = 4 spaces
>=RunTest( "4", lnPasses ) && 2^4 = 16 spaces
>=RunTest( "8", lnPasses ) && 2^8 = 256 spaces
>=RunTest( "16", lnPasses ) && 2^16 = 65,536 spaces
>=RunTest( "20", lnPasses ) && 2^20 spaces
>
>RETURN
>*************************************************************
>FUNCTION RunTest
>
>LPARAMETERS ;
>	tcSpacesExponent ;
>	, tnPasses
>
>?"Spaces: 2^" + tcSpacesExponent ;
>	+ "  Passes: " + LTRIM( STR( tnPasses ) ) ;
>	+ "  Milliseconds: " + LTRIM( STR( Reduce_FoxTools( SPACE( EVALUATE( "2^" + tcSpacesExponent ) ), tnPasses ) ) ) ;
>	+ "  (REDUCE in FoxTools.FLL)"
>
>?"Spaces: 2^" + tcSpacesExponent ;
>	+ "  Passes: " + LTRIM( STR( tnPasses ) ) ;
>	+ "  Milliseconds: " + LTRIM( STR( Reduce_Successive( SPACE( EVALUATE( "2^" + tcSpacesExponent ) ), tnPasses ) ) ) ;
>	+ "  (Reduce_Successive)"
>
>?"Spaces: 2^" + tcSpacesExponent ;
>	+ "  Passes: " + LTRIM( STR( tnPasses ) ) ;
>	+ "  Milliseconds: " + LTRIM( STR( Reduce_Loop( SPACE( EVALUATE( "2^" + tcSpacesExponent ) ), tnPasses ) ) ) ;
>	+ "  (Reduce_Loop)"
>
>RETURN
>*************************************************************
>FUNCTION Reduce_FoxTools
>
>LPARAMETERS ;
>	tcString ;
>	, tnPasses
>
>LOCAL ;
>	lnSeconds ;
>	, lnIx ;
>	, lcString
>
>lnSeconds = SECONDS( )
>
>FOR lnIx = 1 TO tnPasses STEP 1
>	lcString = tcString
>	
>	=REDUCE( lcString )
>
>ENDFOR
>
>RETURN ( SECONDS( ) - lnSeconds ) * 1000
>
>ENDFUNC
>*************************************************************
>FUNCTION Reduce_Successive
>
>LPARAMETERS ;
>	tcString ;
>	, tnPasses
>
>LOCAL ;
>	lnSeconds ;
>	, lnIx ;
>	, lcString
>
>lnSeconds = SECONDS( )
>
>FOR lnIx = 1 TO tnPasses STEP 1
>	lcString = tcString
>	
>	* Code below handles spaces up to 2^20 long (fails on 2^20 + 1)
>
>	lcString = STRTRAN( lcString, [                ], [ ] )
>	lcString = STRTRAN( lcString, [                ], [ ] )
>	lcString = STRTRAN( lcString, [        ], [ ] )
>	lcString = STRTRAN( lcString, [        ], [ ] )
>	lcString = STRTRAN( lcString, [    ], [ ] )
>	lcString = STRTRAN( lcString, [    ], [ ] )
>	lcString = STRTRAN( lcString, [  ], [ ] )
>	lcString = STRTRAN( lcString, [  ], [ ] )
>
>ENDFOR
>
>RETURN ( SECONDS( ) - lnSeconds ) * 1000
>
>ENDFUNC
>*************************************************************
>FUNCTION Reduce_Loop
>
>LPARAMETERS ;
>	tcString ;
>	, tnPasses
>
>LOCAL ;
>	lnSeconds ;
>	, lnIx ;
>	, lcString
>
>lnSeconds = SECONDS( )
>
>FOR lnIx = 1 TO tnPasses STEP 1
>	lcString = tcString
>	
>	DO WHILE [  ] $ lcString
>		lcString = STRTRAN( lcString, [  ], [ ] )
>
>	ENDDO
>	
>ENDFOR
>
>RETURN ( SECONDS( ) - lnSeconds ) * 1000
>
>ENDFUNC
>*************************************************************
>
>The only thing I'm not completely happy about is that the times are also measuring how long it takes to reassign lcString = tcString for the desired number of passes. However, this overhead is exactly the same for all 3 methods.
>
>New results:
>
>Spaces: 2^2  Passes: 100  Milliseconds: 2  (REDUCE in FoxTools.FLL)  
>Spaces: 2^2  Passes: 100  Milliseconds: 1  (Reduce_Successive) 
>Spaces: 2^2  Passes: 100  Milliseconds: 1  (Reduce_Loop) 
>Spaces: 2^4  Passes: 100  Milliseconds: 2  (REDUCE in FoxTools.FLL)  
>Spaces: 2^4  Passes: 100  Milliseconds: 1  (Reduce_Successive) 
>Spaces: 2^4  Passes: 100  Milliseconds: 1  (Reduce_Loop) 
>Spaces: 2^8  Passes: 100  Milliseconds: 4  (REDUCE in FoxTools.FLL)  
>Spaces: 2^8  Passes: 100  Milliseconds: 2  (Reduce_Successive) 
>Spaces: 2^8  Passes: 100  Milliseconds: 9  (Reduce_Loop) 
>Spaces: 2^16  Passes: 100  Milliseconds: 469  (REDUCE in FoxTools.FLL)   
>Spaces: 2^16  Passes: 100  Milliseconds: 132  (Reduce_Successive)  
>Spaces: 2^16  Passes: 100  Milliseconds: 1739  (Reduce_Loop)  
>Spaces: 2^20  Passes: 100  Milliseconds: 9906  (REDUCE in FoxTools.FLL)   
>Spaces: 2^20  Passes: 100  Milliseconds: 4611  (Reduce_Successive)  
>Spaces: 2^20  Passes: 100  Milliseconds: 32510  (Reduce_Loop)
>
>These results are for only 100 passes, rather than 1,000. They are all basically identical for small numbers of spaces. However, when you get into larger numbers of spaces, my technique is fastest, followed by REDUCE in FoxTools, then Chuck's looping technique.

You can not apply a rule based on the 2^power to find
the maximum reduced string with a default number of substitutions.

Reduce_Successive fail on string 456718+1
CLEAR
? 2^20,LEN(Reduce_Successive(SPACE(456718+1)))

FUNCTION Reduce_Successive
LPARAMETERS lcString

	lcString = STRTRAN( lcString, [                ], [ ] )
	lcString = STRTRAN( lcString, [                ], [ ] )
	lcString = STRTRAN( lcString, [        ], [ ] )
	lcString = STRTRAN( lcString, [        ], [ ] )
	lcString = STRTRAN( lcString, [    ], [ ] )
	lcString = STRTRAN( lcString, [    ], [ ] )
	lcString = STRTRAN( lcString, [  ], [ ] )
	lcString = STRTRAN( lcString, [  ], [ ] )

RETURN m.lcString
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform