Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
PADL() has a nice undocumented feature
Message
De
23/02/2006 17:40:56
 
 
À
23/02/2006 14:00:11
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01098313
Message ID:
01098717
Vues:
13
>>Correct documentation is
>>
>>
>>PADL(eExpression, nResultSize [, cExpression])
>>
>>PADR(eExpression, nResultSize [, cExpression])
>>
>>PADC(eExpression, nResultSize [, cExpression])
>>
>>? "Result: " + padl( '', 5, "#_" ) && Result: "#_#_#"
>>
>>* The implementation have a bug
>>? "Result: " + padR( '', 5, "#_" ) && Result: "#_#_#"  Expected "_#_#_"
>>
>
>Your expectation is wrong. This is actually implemented as
>
>
stuff(left(replicate(cExpression, ceiling(nResultSize/len(cExpression)), nResultsize);
>   transform(eExpression), nResultSize-len(transform(eExpression), ;
>   len(transform(eExpression))
>
>
>I.e. VFP repeats the cExpression as needed, then trims it to nResultSize, then stuffs the eExpression in its left, middle or right.

Dragan, VFP don't use stuff logic ( for PADL() it coincides )

I wish STUFF() logic, with control of the boundary fill character:
CLEAR
_screen.FontName="Courier New"
? "padr" at 1,"simulation" at 20,"wish" at 40

testr(123,11,"|_/")
testr(1234,11,"|_/")
testr(12345,11,"|_/")

?
? "padL" at 1,"simulation" at 20,"wish" at 40
testL(123,11,"|_/")
testL(1234,11,"|_/")
testL(12345,11,"|_/")

?
? "padC" at 1,"simulation" at 20,"wish" at 40
testC(123,11,"|_/")
testC(1234,11,"|_/")
testC(12345,11,"|_/")

PROCEDURE testr(a,b,c)
* use multiple character is not useful because the pattern is relative to the eExpression length
? 	PADR(a,b,c)
??	vfppadr(a,b,c) AT 20
* BECAUSE eExpression fill left, i want control the right character
?? wishPadr(a,b,c) AT 40

PROCEDURE testl(a,b,c)
* PADL is OK
? 	PADL(a,b,c)
??	vfppadL(a,b,c) AT 20
* BECAUSE eExpression fill left, i want control the right character
?? wishPadL(a,b,c) AT 40

PROCEDURE testc(a,b,c)
* PADC is out of control
? 	PADC(a,b,c)
??	vfppadC(a,b,c) AT 20
* BECAUSE eExpression fill CENTER, i want control the LEFT AND right character
?? wishPadC(a,b,c) AT 40

FUNCTION vfppadr(eExpression,nResultSize,cExpression)
RETURN transform(eExpression)+left(replicate(cExpression, ceiling(nResultSize/len(cExpression))), nResultsize-LEN(transform(eExpression)))

FUNCTION wishPadr(eExpression,nResultSize,cExpression)
RETURN STUFF(RIGHT(replicate(cExpression, ceiling(nResultSize/len(cExpression))), nResultsize),1,LEN(transform(eExpression)),TRANSFORM(eExpression))

FUNCTION vfppadL(eExpression,nResultSize,cExpression)
RETURN left(replicate(cExpression, ceiling(nResultSize/len(cExpression))), nResultsize-LEN(transform(eExpression)))+transform(eExpression)

FUNCTION wishPadL(eExpression,nResultSize,cExpression)
RETURN STUFF(LEFT(replicate(cExpression, ceiling(nResultSize/len(cExpression))), nResultsize),1+nResultsize-LEN(transform(eExpression)),LEN(transform(eExpression)),TRANSFORM(eExpression))

FUNCTION vfppadC(eExpression,nResultSize,cExpression)
RETURN left(replicate(cExpression, ceiling(nResultSize/len(cExpression))), INT((nResultsize-LEN(transform(eExpression)))/2));
		+transform(eExpression);
		+left(replicate(cExpression, ceiling(nResultSize/len(cExpression))), CEILING((nResultsize-LEN(transform(eExpression)))/2))

FUNCTION wishPadC(eExpression,nResultSize,cExpression)
RETURN STUFF(LEFT(replicate(cExpression, ceiling(nResultSize/len(cExpression))), INT(nResultsize/2));
	+  RIGHT(replicate(cExpression, ceiling(nResultSize/len(cExpression))), CEILING(nResultsize/2));
		, CEILING((1+nResultsize-LEN(transform(eExpression)))/2);
		, LEN(transform(eExpression)),TRANSFORM(eExpression))
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform