InStr, InStrB Functions

Named Arguments

No

Syntax

InStr([start, ]stringtosearch, stringtofind[, _
      comparemode])


start

Use: Optional

Data Type: Numeric

The starting position for the search.


stringtosearch

Use: Required

Data Type: String

The string being searched.


stringtofind

Use: Required

Data Type: String

The string being sought.


comparemode

Use: Optional

Data Type: Integer

The type of string comparison.

Return Value

A variant of subtype Long.

Description

Finds the starting position of one string within another.

Rules at a Glance

  • The return value of InStr is influenced by the values of stringtosearch and stringtofind, as the following table details:

    Condition InStr Return Value
    stringtosearch is zero-length 0
    stringtosearch is Null Null
    stringtofind is zero-length start
    stringtofind is Null Null
    stringtofind is not found 0
    stringtofind found within stringtosearch Position at which the start of stringtofind is found
    start > len(stringtofind) 0

  • If the start argument is omitted, InStr commences the search with the first character of stringtosearch.

  • If the start argument is Null, an error occurs.

  • You must specify a start argument if you are specifying a comparemode argument.

  • VB5 and VBA support intrinsic constants for comparemode, as follows:

    Comparison Mode Value Constant
    Binary (default) 0 vbBinaryCompare
    Text—case insensitive 1 vbTextCompare
    Database (Microsoft Access only) 2 vbDatabaseCompare

  • If the comparemode argument contains Null, an error is generated.

  • If comparemode is omitted, the type of comparison is determined by the Option Compare setting.

Programming Tips and Gotchas

You can use the InStrB function to compare byte data contained within a string. In this case InStrB returns the byte position of stringtofind, as opposed to the character position.

See Also

InStrRev Function, Left Function, Mid Function, Option Compare Statement, Right Function, StrComp Function
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.61.22