Fandom

Livecode Wiki

Find

1,968pages on
this wiki
Add New Page
Comments0 Share

Find is a useful command to search through all fields in the current card or in a particular field. To search in all fields, except those fields with property dontSearch set as true:

find "example"

To search in a particular field

find "example" in field "long text"

The find command starts searching after the previously-found text (if there was a previous find command) or at the beginning of the first field on the current card (if not).

When the search is successful, the card containing the text appears and a box is drawn around the found text. If the text is not found in the stack, the result function returns "Not found".

Find1

Find example

Moreover there are several type of search, that you may decide declaring also a parameter: The parameter is one of the following words:

  • normal
  • characters or character (or chars or char)
  • words or word
  • string
  • whole
  • empty

Example:

find string "example" in field "long text"

If no form is specified, the find normal form is used.

The six forms of the find command search in different ways. The find normal, find chars, and find words forms search for each word in the textToFind, but the words don't have to be together to be found; they only have to all appear on the same card. The find words and find wholeforms look for complete words only. The find string and find whole forms search for the textToFind as a unit.

The find normal form looks for each word in the textToFind at the beginning of a word. For example, find "ring bell" finds "ringing" and "belltower", but not "bring" or "Campbell". All the words you specify must be in fields on the card, but they don't need to be in the same order, or even in the same field.

The find chars form looks for each word in the textToFind, in any part of a word. Unlike the find normal form, the find chars form doesn't require that the words in the textToFind be found at the start of a word on the card. For example, find chars "ring bell" finds "bring", "ringing", "belltower", and "Campbell". As with the find normal form, all the words must be somewhere on the card, but they don't need to be in the same order, or in the same field.

The find words form looks for each word in the textToFind. All the words must be complete words, not parts of words. For example, find words "ring bell" finds "ring" and "bell", but not "ringing", "bring", "belltower", or "Campbell". As with the find normal and find chars forms, all the words must be somewhere on the card, but they don't need to be in the same order, or in the same field.

The find string form looks for the entire textToFind as a unit. Unlike the find normal, find chars, and find words forms, the find string form requires that the textToFind be found exactly: the words must be in the same order and in the same field, and not separated by other words. For example, find string "ring bell" finds "ring bell" and "bring belltower", but not "ring the bell" (extra word between "ring" and "bell"), "Ringbell Street" (no space between "ring" and "bell"), or "bell ringer" (words are in the wrong order).

The find whole form looks for the entire textToFind as a unit. Like the find words form (and unlike the find string form), the find whole form requires that each word in the textToFind be found as a whole word, not part of a word. For example, find whole "ring bell" finds "ring bell", but not "bring belltower" (the "ring" and "bell" are parts of words, not whole words), "ring the bell" (extra word between "ring" and "bell"), "Ringbell Street" (no space between "ring" and "bell"), or "bell ringer" (words are in the wrong order).

Note: Because the find normal, find words, and find whole forms search for words or portions of words, they cannot find a string containing a space. The find string form can find a string containing a space, but cannot find a string that contains a return character.

The find empty form of the find command removes the box from the last word found and resets the find command, so that the next search starts from the beginning of the current card, rather than the location of the next find. Going to another card also resets the find command.

The setting of the caseSensitive property determines whether the search considers uppercase and lowercase characters to be equivalent.

Note: The search does not consider characters that differ by a diacritical mark to be equivalent. For example, find "mére" will not find the word "mere".

Usually, the offset and matchText functions are faster than the find command. But unlike these functions, the find command can search all the fields of a stack at once, instead of one container at a time.

Better looking searchEdit

There are two special variables that you can use for further use, foundText and foundChunk. The first contains just the text found from the last find executed, the other one is a complete chunk that identify all aspect of the founded text. For example, you can use the foundChunk variable to change effect when the text is found. The following code:

  lock screen 
  if exists(graphic "greenmark") then
     delete graphic "greenmark"
  end if
  put the numfind of me into n
  if n is empty then 
     put 1 into n
  end if
  put the text of field "textToFind" into parola
  put the oldparola of me into oldpar
  if oldpar is not parola then
     put 1 into n
  end if
  repeat for n times
     find parola in field "longtext"
  end repeat   
  set the oldparola of me to parola
  if the foundchunk is not empty then
     put the foundchunk into temp
     find empty      
     create graphic "greenmark" 
     set the style of graphic "greenmark" to "roundrect"
     set the linesize of graphic "greenmark" to 3
     set the foregroundcolor of graphic "greenmark" to "green"
     put the formattedrect of temp into tempRect
     add -4 to item 1 of tempRect
     add -4 to item 2 of tempRect
     add 4 to item 3 of tempRect
     add 4 to item 4 of tempRect
     set the rect of graphic "greenmark" to tempRect
     add 1 to n
     set the numfind of me to n
  else 
     set the numfind of me to empty
  end if   
  unlock screen
Find2

custom find example

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.