InStr Function
Updated: September 2010
Returns the position of the first occurrence of one string within another.
InStr([start, ]string1, string2[, compare])
The following examples use InStr to search a string:
Dim MyPos
' This is a binary comparison because the last argument is omitted.
' Returns 3.
MyPos = InStr ("abcdefgh", "c")
' In this binary comparison, the uppercase "C" is not found
' in the lowercase string.
' Returns 0 (not found).
MyPos = InStr ("abcdefgh", "C")
' In this text comparison starting at the first position,
' the uppercase "C" is found in the lowercase string.
' Returns 3.
MyPos = InStr (1, "abcdefgh", "C", vbTextCompare)
Note:
|
|---|
|
The InStrB function is used with byte data contained in a string. Instead of returning the character position of the first occurrence of one string within another, InStrB returns the byte position. |
The function does not handle more than 17 characters i String2
I want to compare string1 "D:\Access\LongRunners\Ny_HentLongRunners.vbs" with string2 "Ny_HentLongRunners.vbs" to get the start of my 'trim left' statement.
The string2 argument is in fact a variable containing the scriptname.
However: It does not work and I narrowed it down to that not more than 17 characters can be compared at a time.
This is not obvius and is not described in the reference.
bs
- 8/13/2011
- brv64b
Note: