Simplicty and flexibility!


TextPos("This is a text with more text in it","Text",2) -- Will return position of the second occurrence of Text
retval := TextPos(MyField,MySearch,MyOccurence) --

The textpos function is not case sensitive (no distinction is made between upper and lower case letters).

If the substring is contained in the specified text value, the starting position of the first (leftmost) character in the substring is returned.

If the substring is not contained in the text value, the function returns 0. Intervening spaces and punctuation symbols are included in the calculation. Trailing spaces are ignored.

To find the starting position of a search string in a string. In 8.6 and later you have optional argument for occurrence number i.e. if you want to find the start position of the third occurrence of "Name" you simply add ,3 at the end.

Occurrence is a new feature in 8.6 and will not work in 8.5 or lower.

TextPos is converted to LargeText function in 8.6 and will now allow searching in text up to 4GB,old size was 255 characters.


String: String To search. (LargeString 8.6 onwards)
String: String to Search for (LargeString 8.6 onwards).

Number: Occurrence to search for in string


Position in string of search string (occurence)



textpos("Buccaneer's Creek","can")

Returns: 4

textpos("Sapphire International","national")

Returns: 15

textpos(CLUB NAME,"bus"),

Returns: The first position of the string bus in every record that is processed. If a record contains thevalueColumbus Island in the CLUB NAME field, the function returns 6.

Note: textpos interprets wildcard symbols like ?*? as a character, rather than a wildcard. It can therefore be used to detect the presence of such wildcard characters in a text string


See Also

On the forum about Textpos

On the blog about Textpos