Find - find a substring inside a string

Return to Introduction  Previous page  Next page

$return = find(stringToSearch,stringToFind[,start][,USEWILDCARDS])


$returnreceives the position, relative to 1, where stringToFind first appears in stringToSearch. If the string is not found,  "0" (zero) is returned.
stringToSearchthe string to be searched. Enclose stringToSearch in double quotation marks ("") if it contains embedded spaces or commas.
stringToFindthe string to find in stringToSearch. Enclose stringToFind in double quotation marks ("") if it contains embedded spaces or commas. When the "USEWILDCARDS" parameter is specified, this parameter may contain wildcards and a pattern matching search is done. The following wildcards may be used:

Wildcard Characters

Matches in the search string


Any single character


Zero or more characters


Any single numeric digit


Any single character in charlist


Any single character not in charlist


charlist is a group of one or more characters enclosed in brackets ([]) and can be used to match any single character in a string. It may include any of the following characters:

Almost any character in the ANSI character set including digits
The special characters opening bracket ([), question mark (?), number sign (#) and asterisk (*) can be used for matching only if enclosed in brackets. The closing bracket (]) can't be used within a charlist to match itself, but it can be used outside the group as an individual character. A hyphen (-) can be used at the beginning or end of charlist to match itself. In any other position it indicates a range of characters.
A range of characters can be specified by placing a hyphen between lower and upper bounds. For example, [a-z], [A-Z] or [0-9]. Multiple ranges can be specified without any delimiter. For example [a-zA-Z0-9] matches any alphanumeric character. When a range of characters is specified they must appear in ascending sort order. [A-Z] is valid, but[Z-A] is not.


startan optional parameter that specifies the position, relative to 1, within stringToSearch where the find operation should begin.
USEWILDCARDSuse pattern matching when performing the search.        


stringToSearch, stringToFind and start may be variables.

The find command finds a string within another string and returns the position of the found string in a variable. If the string is not found, "0" (zero) is returned. If the USEWILDCARDS parameter is specified, wildcard characters may be specified in the stringToFind parameter and a pattern matching search is performed.



$Position = Find("The quick brown fox",fox)

$Position = Find("Doe, John 123-456-7890",###[-]###[-]####,USEWILDCARDS)

$Position = Find($string1,$string2,10)

$Position = Find($SCREEN,Login:)


See Also:


Script Command Summary

Script Variables

Using the Scripting Language

TN3270 Plus is continually being improved. To learn more about the latest enhancements, please review our Version History web page.