General information
Category:
Coding, syntax & commands
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
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only