search(
TEXT
,
PHRASE
)

The search( function searches through an item of text looking for a character, word or phrase. If it finds an exact match (including upper/lower case) with the character, word or phrase, it returns its position within the text item. If it does not find the character, word or phrase, it returns zero.


Parameters

This function has two parameters:

text – is the item of text that you want to search through.

phrase – is the character, word or phrase that you want to search for. This must be the exact character, word, or phrase, including upper or lower case. The search( function will not match Dr with DR or dr. If you don’t care about upper/lower case, use the searchanycase( function.


Description

This simple procedure uses the search( function to attempt to locate and display a fax number in the Notes field. This procedure assumes that the fax number will look something like this: fax (999) 555–0123.

local X X=search(lower(Notes),"fax (")
if X<>0
    message "Fax Number: "+Notes[X+4;14]
endif

The example starts by searching for the phrase fax (. If it finds this phrase, it displays the 14 characters starting with the ( symbol. (By using the lower( function the procedure makes sure that *search(* will find a match even if the word fax is all or partially in upper case.) By removing the text that has already been searched through, a procedure can locate multiple occurrences of a character, word or phrase. This procedure attempts to locate every phone number and collect them all into a list.

local X,XNotes,XPhone,PhoneList
X=1
XNotes=Notes
PhoneList=""
loop
    X=search(XNotes,"(")
    stoploopif X=0
    XPhone=XNotes[X;14]
    if XPhone match "(???) ???-????"
        PhoneList=sandwich("",PhoneList,",")+XPhone
        X=X+14
    endif
    XNotes=XNotes[X+1,-1]
while forever
message "Phone Numbers: "+PhoneList

After each successful search, the procedure lops off the section of the text that has already been searched, and then starts over again. The process continues until there are no more matches.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0, however, this function now automatically converts numbers to text before performing the search.