Method

InStrB


Warning

This item was deprecated in version 2019r2. Please use String.IndexOfBytes as a replacement.

Description

Returns the byte position of the first occurrence of a string inside another string. The first character is numbered 1.

Usage

result=InStrB([start,] source, find)

OR

result=stringVariable.InStrB([start], find)

Part

Type

Description

result

Integer

The byte position of the first occurrence of find in source.

start

Integer

Optional byte position from which to begin searching the source string. One is the default if omitted.

source

String

Required. String expression being searched.

find

String

Required. String expression being sought.

stringVariable

String

Any variable of type String.

Notes

If the find string is not found within the source string, 0 (zero) is returned. InStrB is case-sensitive; it treats source as a series of raw bytes. It should be used instead of String.IndexOf when the string represents binary data or when your application will run in a one-byte character set (such as the US system) and you want case-sensitivity.

If you need to find the character position of the find string within the source string, use the String.IndexOf function.

Sample code

This example uses the InStrB function to locate a string within another string.

Dim first As Integer
first = InStrB("This is a test", "T") ' returns 1
first = InStrB("This is a test", "t") ' returns 11
first = InStrB("This is a test", "is") ' returns 3
first = InStrB(4, "This is a test", "is") ' returns 6
first = InStrB("This is a test", "tester") ' returns 0
first = InStrB("This Is a test", "Is") ' returns 6

Dim s As String = "This is a test"
first = s.InStrB("test") ' returns 11

Compatibility

All project types on all supported operating systems.