
It is also useful for optimizing calls to InStr. Position = InStr(4, "avbprogramvb", "vb") This allows us to skip known instances of the search string. The start parameter is useful to skip the start of the string. Position = InStr("avbprogram", "v") Search in the rest of the string Position = InStr("avbprogramvb", "vb") Locate the first character in a string ' Returns 2 In the following examples we assume that Option Compare Binary is in effect. If you are only passing String data, you are safe. You can only receive a Null if you are passing Variant data to InStr and if the data can contain a Null.
#Visual basic string function code#
If your code is not prepared to receive a Null, it may crash. If start exceeds the length of string1, there is never a match and InStr returns 0.Ĭrash warning.InStr( string1, "") returns 1 if string1 is not empty.In text comparison, what matches on one computer may not match on another. Text comparison rules vary by the system locale. If you omit compare, InStr will use the setting of the Option Compare statement.īinary comparison is the safest option.For Microsoft Access (Windows only), performs a comparison based on information contained in your database. vbTextCompare (1) performs a text comparison.vbBinar圜ompare (0) performs a fast binary comparison where each character matches only itself.This is the text you want to find inside string1. Valid input values: 1 to Len( string1) string1 The string to search in. If omitted, the search starts at the start of string1, position 1. Character position where the search starts. InStr( string1, string2 ) start Optional. InStr returns the first occurrence of a string inside another string. VB6 statements and constants in this article: InStr, InStrB, InStrRev, Option Compare, vbBinar圜ompare, vbTextCompare.
