Vbs Tutorial: function-instr Function

Source: Internet
Author: User

Instr Functions

Returns the position where a string appears for the first time in another string.

Instr ([Start,] string1, string2 [, compare])

Parameters

Start

Optional. Value expression, used to set the start position of each search. If omitted, the search starts from the first character. IfStartIf it contains null, an error occurs. IfCompare, You must haveStartParameters.

String1

Required. String expression to be searched.

String2

Required. The string expression to be searched.

Compare

Optional. Indicates the value of the comparison type used to calculate the substring. For values, see the "Settings" section. If omitted, binary comparison is executed.

Set

CompareParameters can have the following values:

Constant Value Description
Vbbinarycompare 0 Perform binary comparison.
Vbtextcompare 1 Execute text comparison.

Return Value

InstrThe function returns the following values:

If Instr return
String1 0 Length 0
String1 is null Null
String2 0 Length Start
String2 is null Null
String2 not found 0
Find string2 in string1 Locate the position that matches the string
Start> Len (string2) 0

Description

The following example usesInstrSearch string:

Dim searchstring, searchchar, mypossearchstring = "xxpxxpxxpxxp" 'string to search in. searchchar = "p" 'search for "p". Mypos =Instr (4,Searchstring,Searchchar,1)     'A textual comparison starting at position 4. Returns 6.  Mypos =Instr (1,Searchstring,Searchchar,0)     'A binary comparison starting at position 1. Returns 9.  Mypos =Instr (Searchstring,Searchchar)    'Comparison is binary by default (last argument is omitted). Returns 9.  Mypos =Instr (1,Searchstring,"W")     'A binary comparison starting at position 1. returns 0 ("W" is not found ). 

Note: Limit BThe function uses the byte data contained in the string, soLimit BThe returned result is not the first occurrence of a character string in another string, but the byte position.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.