Method: InStr for VBS
- Updated2024-09-12
- 2 minute(s) read
Methods > Method: InStr for VBS
Method: InStr for VBS
Specifies the position in the text where a character or a character string appears in the text for the first time.
vInStr = Object.InStr(start, string, string2, [compare])
| Object | VBS Object with this method. You do not need to specify this object. | ||||||||||||||
| start | Variant Specifies the start position of the search. If you do not specify start, the search starts with the first character. If you specify compare, you must also specify start. If you do not specify compare, you need not specify start. | ||||||||||||||
| string | Variant Specifies the text you want to search through. | ||||||||||||||
| string2 | Variant Specifies the character string you want to search for. | ||||||||||||||
| [compare] | Variant Specifies the type of comparison. Possible settings are vbBinaryCompare and vbTextCompare. If you do not specify compare, the InStr method performs a binary comparison. | ||||||||||||||
| vInStr | Variant Receives the position of a character or a character string in a text. Possible return values:
|
The following example searches a text in various character strings:
Dim MyPos MyPos = InStr("abcdabcde", "c") 'Returns 3 Call MsgBox(MyPos) MyPos = InStr("abcdabcde", "C") 'Returns 0 Call MsgBox(MyPos) MyPos = InStr(1, "abcdabcde", "C", vbTextCompare) 'Returns 3 Call MsgBox(MyPos)