SET TALK OFF
a='2222222221111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222111112348888'
b='1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111165'
?minus(a,b)
RETURN
FUNCTION minus
LPARAMETERS cStr1,cStr2
IF TYPE('cStr1')#'C' OR !ALLTRIM(cStr1)==CHRTRAN(cStr1,CHRTRAN(cStr1,'0123456789',''),'')
RETURN ''
ENDIF
IF TYPE('cStr2')#'C' OR !ALLTRIM(cStr2)==CHRTRAN(cStr2,CHRTRAN(cStr2,'0123456789',''),'')
RETURN ''
ENDIF
LOCAL lnLen,lcStra,lcStrb,lcSign,lcRes,lnCnt,llIs,lnDegit1,lnDegit2
lnLen=MAX(LEN(ALLTRIM(cStr1)),LEN(ALLTRIM(cStr2)))
lcStra=MAX(PADL(ALLTRIM(cStr1),lnLen,' '),PADL(ALLTRIM(cStr2),lnLen,' '))
lcStrb=MIN(PADL(ALLTRIM(cStr1),lnLen,' '),PADL(ALLTRIM(cStr2),lnLen,' '))
lcSign=IIF(lcStra==PADL(ALLTRIM(cStr1),lnLen,' '),'','-')
lcRes=''
llIs=.F.
FOR lnCnt=1 TO lnLen
lnDegit1=VAL(SUBSTR(lcStra,lnLen-lnCnt+1,1))
lnDegit2=VAL(SUBSTR(lcStrb,lnLen-lnCnt+1,1))
DO CASE
CASE llIs=.T. AND lnDegit1-1>=lnDegit2
lcRes=STR(lnDegit1-1-lnDegit2,1)+lcRes
llIs=.F.
CASE llIs=.T. AND lnDegit1-1< lnDegit2
lcRes=STR(lnDegit1-1+10-lnDegit2,1)+lcRes
llIs=.T.
CASE llIs=.F. AND lnDegit1
>=lnDegit2
lcRes=STR(lnDegit1-lnDegit2,1)+lcRes
llIs=.F.
CASE llIs=.F. AND lnDegit1
< lnDegit2
lcRes=STR(lnDegit1+10-lnDegit2,1)+lcRes
llIs=.T.
ENDCASE
ENDFOR
DO WHILE lcRes='0'
lcRes=SUBSTR(lcRes,2)
ENDDO
RETURN lcSign+lcRes