Syntax
InStr([Index,] Source$, Search$)
Remarks
Returns the character position in Source$ at which Search$ begins, where 1 corresponds to the first character, 2 to the second character, and so on. If Source$ does not contain Search$, InStr() returns 0 (zero).
Argument | Explanation |
Index | The character position in Source$ at which to begin the search |
Source$ | The text to be searched |
Search$ | The text to search for |
Examples
This example sets the variable pos to 7:
list$ = "Bonn, Paris, Tokyo" city$ = "Paris" pos = InStr(list$, city$)
The following example sets pos to 15. Note that if Index were not specified, pos would be 2.
pos = InStr(3, "Bonn, Paris, Tokyo", "o")
The following example, which assigns an MS-DOS filename with a filename extension to name$, defines prefix$ as the filename without the extension:
name$ = "SUMMARY.DOC" dot = InStr(name$, ".") If dot > 1 Then prefix$ = Left$(name$, dot - 1)
See Also
Left$(), Len(), LTrim$(), Mid$(), Right$(), RTrim$()