Wiki Home

Un Padl


Namespace: Wiki
FUNCTION UnPadL
* Return a string from an expression with char(s) removed from the left
LPARAMETERS tuExp, tcUnpadChar
LOCAL lcExp, lnThisChar, lnUnpadLen
	IF VARTYPE(tcUnpadChar) <> "C"
		RETURN tuExp
	ENDIF
	IF VARTYPE(tuExp) <> "C"
		lcExp = LTRIM(TRANSFORM(tuExp))
	ELSE
		lcExp = LTRIM(tuExp)
	ENDIF
	lnUnpadLen = LEN(tcUnpadChar)
	lnThisChar = 1
	DO WHILE SUBSTR(lcExp, lnThisChar, lnUnpadLen) == tcUnpadChar
		lnThisChar = lnThisChar + lnUnpadLen
	ENDDO
	lcExp = SUBSTR(lcExp, lnThisChar)
	RETURN lcExp
ENDFUNC
*------------------------
FUNCTION UnPadLValidation
LPARAMETERS luParm1, luParm2, lcExpected
	IF UnPadL(luParm1, luParm2) <> lcExpected
		ERROR "Expected '" + lcExpected + "' from 'UnPadL' but got " + UnPadL(luParm1, luParm2)
	ENDIF
ENDFUNC
*-------------------------
FUNCTION UnPadLValidations
	UnPadLValidation("wxwxwx1234", "wx", "1234")
	UnPadLValidation("00001234", "0", "1234")
	UnPadLValidation("01010101234", "01", "234")
	UnPadLValidation("12340000", "0", "12340000")
	UnPadLValidation(12340000, "0", "12340000")
	UnPadLValidation(12340000, "1", "2340000")
	UnPadLValidation("ABRACADABRA", "ABRA", "CADABRA")
	UnPadLValidation("z!z!z!ABC", "z!", "ABC")
ENDFUNC

Submitted by Joe Kuhn (and others)
Category Code Samples
( Topic last updated: 2001.11.15 04:15:48 PM )