VBspeed / String / InStr
VBspeed © 2000-10, updated: 05-Oct-2002
InStr
See also InStrRev


The Definition
Function InStr
Returns the position of the first occurrence of one string within another.
Native to VB5 and VB6 (actually to all versions of VB, even to all versions of BASIC, AFAIK).
VBspeed's Declaration:
InStr(sCheck, sMatch[, Start[, Compare]])
VB's native Declaration:
VB's InStr, of course, looks like this (with the optional Start parameter as the first argument, a weird setup if you ask me):
InStr([Start, ]sCheck, sMatch[, Compare])
Arguments:
sCheckRequired. String expression being searched.
sMatchRequired. String expression being searched for.
StartOptional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position (Start = 1).
CompareOptional. Numeric value indicating the kind of comparison to use when evaluating substrings. If omitted, a binary comparison is performed.
Return Values:
Typical cases:
InStr("abc", "a")             =>  1
InStr("abc", "b")             =>  2

Special cases:
sCheck is zero-length         =>  0
sMatch is zero-length         =>  start
sMatch is not found           =>  0
Start > Len(sMatch)           =>  0
Roll your own
If you want to have a go at InStr yourself, use this function (VB5/6-compatible) to verify the correctness of your code.


The Charts
Calls
  lRet = InStr(sCheck, sMatch, , Compare)
Call 1 sCheck = "http://www.xbeat.net/vbspeed/index.htm"
sMatch = ":"
Call 2 sCheck = "http://www.xbeat.net/vbspeed/index.htm"
sMatch = "."
Call 3 sCheck = "http://www.xbeat.net/vbspeed/index.htm"
sMatch = "m"
Call 4 sCheck = "http://www.xbeat.net/vbspeed/index.htm"
sMatch = "M"
Compare = vbTextCompare
Call 5 sCheck = "http://www.xbeat.net/vbspeed/index.htm"
sMatch = "www"
Call 6 sCheck = "http://www.xbeat.net/vbspeed/index.htm"
sMatch = "WWW"
Compare = vbTextCompare
Call 7 sCheck = Space$(999) & String$(99, "x") & Space(99)
sMatch = "x"  [many occurrences, but very far from left end]
Call 8 sCheck = Space$(100)
sMatch = "x"  [no occurrences]
 VB5
CodeAuthorDopingNotes
InStr VB5/6  
InStr01 MarzoAPI 
Call 1
21.080.070Ás
11.000.065Ás
Call 2
11.000.076Ás
21.250.094Ás
Call 3
11.000.094Ás
21.360.128Ás
Call 4
28.071.311Ás
11.000.162Ás
Call 5
11.000.080Ás
21.210.097Ás
Call 6
211.061.328Ás
11.000.120Ás
Call 7
11.001.415Ás
22.303.256Ás
Call 8
11.000.182Ás
21.990.361Ás
 VB6
CodeAuthorDopingNotes
InStr VB5/6  
InStr01 MarzoAPI 
Call 1
11.000.063Ás
21.020.064Ás
Call 2
11.000.072Ás
21.280.092Ás
Call 3
11.000.087Ás
21.400.122Ás
Call 4
28.221.306Ás
11.000.159Ás
Call 5
11.000.076Ás
21.190.090Ás
Call 6
210.671.309Ás
11.000.123Ás
Call 7
11.001.414Ás
22.173.065Ás
Call 8
11.000.183Ás
21.760.322Ás
Conclusions
It's not easy to defeat native InStr, but there's good news for people that have to use InStr in TextCompare mode.
Mail your code! How to read all those numbers


The Code
InStr01
submitted 05-Oct-2002 by Marzo Junior  
Doping: TLB (cf. Dope'n'Declarations)
Class-wrapped. The class, which also includes a bunch of related functions, is waiting for you here.
Author's comments:
Donald's comments:

top | charts




VBspeed © 2000-10 by Donald Lessau