INSTR Function ---------------------------------------------------------------------------- Action Returns the character position of the first occurrence of a string in another string. Syntax INSTR( start%, stringexpression1$, stringexpression2$) Remarks The INSTR function uses the following arguments. ----------------------------------------------------------------------------- Argument Description ---------------------------------------------------------------------------- start% An optional offset that sets the position for starting the search; start% must be between 1 and 32,767, inclusive. If start% is Argument Description ---------------------------------------------------------------------------- 32,767, inclusive. If start% is not given, the INSTR function begins the search at the first character of stringexpression1$. stringexpression1$ The string being searched. stringexpression2$ The string to look for. The arguments stringexpression1$ and stringexpression2$ can be string variables, string expressions, or string literals. The value returned by INSTR depends on these conditions. ----------------------------------------------------------------------------- Condition Value returned Condition Value returned ---------------------------------------------------------------------------- stringexpression2$ found in The position at which the match is stringexpression1$ found start% greater than length of 0 stringexpression1$ stringexpression1$ is a null string 0 stringexpression2$ cannot be found 0 stringexpression2$ is a null string start% (if given); otherwise, 1 Use the LEN function to find the length of stringexpression1$. See Also LEN Example The following example uses INSTR and UCASE$ to determine a person's gender from a courtesy title (Mr., Mrs., or Ms.). CLS ' Clear screen. DO INPUT "Enter name with courtesy title (Mr., Mrs., or Ms.). ", Nm$ LOOP UNTIL LEN(Nm$) >= 3 Nm$ = UCASE$(Nm$) ' Convert lowercase letters to uppercase. ' Look for MS, MRS, or MR to set Sex$. IF INSTR(Nm$, "MS") > 0 OR INSTR(Nm$, "MRS") > 0 THEN Sex$ = "F" ELSEIF INSTR(Nm$, "MR") > 0 THEN Sex$ = "M" ELSE ' Can't determine gender, query user. DO INPUT "Enter sex (M-F). ", Sex$ Sex$ = UCASE$(Sex$) LOOP WHILE Sex$ <> "M" AND Sex$ <> "F" END IF PRINT "Sex is "; Sex$ Output Enter name. Ms. Elspeth Brandtkeep Sex is F Enter name. Dr. Richard Science Enter sex (M-F). M Sex is M