Information générale
Catégorie:
Codage, syntaxe et commandes
John,
I could not sleep last night and your problem kept nagging at me.
So here is a solution (that you can improve upon I am sure).
The following function will look anywhere in a string for a pattern
of numbers and alphas (*#* #*# for a canadian postal code) and
return the portion of the string that match your pattern or the
empty string otherwise.
Function FindPattern
lparameter cPattern,cString
local iLen,iPos,cSubStr,i,lMatchFound
iLen=len(cPattern)
iPos=1
lMatchFound=.f.
do while iPos+iLen-1<=len(cString)
cSubStr=substr(cString,iPos,iLen)
lMatchFound=.t.
i=1
do while i<=iLen
do case
case substr(cPattern,i,1)='#'
if not isdigit(substr(cSubStr,i,1))
lMatchFound=.f.
exit
endif
i=i+1
case substr(cPattern,i,1)='*'
if not isalpha(substr(cSubStr,i,1))
lMatchFound=.f.
exit
endif
i=i+1
otherwise
i=i+1
endcase
enddo
if lMatchFound
return cSubStr
endif
iPos=iPos+1
enddo
return ''
Hope this helps.
This was a fun one to do.
:)
Pascal
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement