Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
? SUBSTREX( 'TOULOUSE', 4, 1) && returns "L"
? SUBSTREX( 'TOULOUSE', 4, -2) && returns "LU"
? SUBSTREX( 'TOULOUSE', -4, 2) && returns "OU"
? SUBSTREX( 'TOULOUSE', -4, -2) && returns "OL"
? SUBSTREX( 'TOULOUSE', 2) && returns "OULOUSE"
? SUBSTREX( 'TOULOUSE', -3) && returns "USE"
? SUBSTREX( ' TOULOUSE', 5, -5, .F. ) && returns "LUOT "
? SUBSTREX( ' TOULOUSE', 5, -5, .T. ) && returns "LUOT"
FUNCTION SUBSTREX()
LPARAMETERS tcString, tnPos, tnLen, tlAllTrim
LOCAL lcResult, lnFor, lcBitOfString
lcResult = ""
*** Check Parms
IF TYPE('tcString') = 'C' AND TYPE('tnPos') = 'N' AND (TYPE('tnLen') = 'L' OR TYPE('tnLen') = 'N' ) AND Type('tlAlltrim') = 'L'
IF tlAllTrim
tcString = ALLTRIM(tcString)
ENDIF
IF tnPos < 0
tnPos = LEN(tcString) - ABS(tnPos) + 1
ENDIF
DO CASE
CASE TYPE('tnLen') = 'L'
*** Return all from starting position if no second parm is passed
lcResult = SUBSTR( tcString, tnPos)
CASE tnLen > 0
*** Standard SUBSTR() - Read left to right
lcResult = SUBSTR(tcString, tnPos, tnLen)
CASE tnLen < 0
tnLen = ABS(tnLen)
IF tnLen > tnPos
tnLen = tnPos
ENDIF
*** Read from left for starting position, read right to left for result
lcBitOfString = SUBSTR(tcString, tnPos - tnLen + 1, tnLen)
FOR lnFor = tnLen TO 1 STEP -1
lcResult = lcResult + SUBSTR(lcBitOfString, lnFor, 1)
ENDFOR
ENDCASE
ENDIF
RETURN lcResult
ENDFUNC