Instr/InstrRev: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
(Created page with "INSTR([''start'', ]''string1'', ''string2''[, ''compare'']) INSTRREV(''string1'', ''string2''[, ''start''[, ''compare'']]) '''Description''' INSTR returns a long value spec...")
 
No edit summary
Line 1: Line 1:
INSTR([''start'', ]''string1'', ''string2''[, ''compare''])
Instr([''start'', ]''string1'', ''string2''[, ''compare''])


INSTRREV(''string1'', ''string2''[, ''start''[, ''compare'']])
InstrRev(''string1'', ''string2''[, ''start''[, ''compare'']])


'''Description'''
== Description ==


INSTR returns a long value specifying the position of one string within another, measured from the start of the string searched.  
Instr returns a long value specifying the position of one string within another, measured from the start of the string searched.  


INSTRREV returns a long value specifying the position of one string within another, measured from the end of the string searched.  
InstrRev returns a long value specifying the position of one string within another, measured from the end of the string searched.  


The optional parameter, ''start'', is a numeric expression that specifies the starting position of the search within the target string. If start is not provided, the search defaults to 1, the first character position for INSTR, or -1, the last character position for INSTRREV. The required parameter, ''string1'', is the string being searched. The required parameter, ''string2'', is the string that is being searched for. The optional parameter, ''compare'', is used to specify the type of search performed. If string2 is found in string1, a positive integer is returned with 0 being the location of the first character, otherwise -1 is returned if string2 is not found in string1.
The optional parameter, ''start'', is a numeric expression that specifies the starting position of the search within the target string. If start is not provided, the search defaults to 1, the first character position for INSTR, or -1, the last character position for INSTRREV. The required parameter, ''string1'', is the string being searched. The required parameter, ''string2'', is the string that is being searched for. The optional parameter, ''compare'', is used to specify the type of search performed. If string2 is found in string1, a positive integer is returned with 0 being the location of the first character, otherwise -1 is returned if string2 is not found in string1.


'''Example'''
== Example ==


<pre>
<pre>
REM INSTR/INSTRREV finds a string in another
Rem Instr/InstrRev finds a string in another
DIM Pos1, Pos2
Dim Pos1, Pos2
Pos1 = INSTR("Cartman", "man")
Pos1 = Instr("Cartman", "man")
Pos2 = INSTRREV("Big Al's Big Boat Ride", _
Pos2 = InstrRev("Big Al's Big Boat Ride", _
       "big", 4, vbTextCompare)
       "big", 4, vbTextCompare)
PRINT "Finding ""man"" from start:", Pos1
Print "Finding ""man"" from start:", Pos1
PRINT "Finding ""big"" from end:", Pos2
Print "Finding ""big"" from end:", Pos2
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 29: Line 29:
Finding "big" form end:    1
Finding "big" form end:    1
</pre>
</pre>
[[Category:Language Reference]]

Revision as of 01:39, 17 August 2012

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

InstrRev(string1, string2[, start[, compare]])

Description

Instr returns a long value specifying the position of one string within another, measured from the start of the string searched.

InstrRev returns a long value specifying the position of one string within another, measured from the end of the string searched.

The optional parameter, start, is a numeric expression that specifies the starting position of the search within the target string. If start is not provided, the search defaults to 1, the first character position for INSTR, or -1, the last character position for INSTRREV. The required parameter, string1, is the string being searched. The required parameter, string2, is the string that is being searched for. The optional parameter, compare, is used to specify the type of search performed. If string2 is found in string1, a positive integer is returned with 0 being the location of the first character, otherwise -1 is returned if string2 is not found in string1.

Example

Rem Instr/InstrRev finds a string in another
Dim Pos1, Pos2
Pos1 = Instr("Cartman", "man")
Pos2 = InstrRev("Big Al's Big Boat Ride", _
       "big", 4, vbTextCompare)
Print "Finding ""man"" from start:", Pos1
Print "Finding ""big"" from end:", Pos2

Output

Finding "man" from start:  5
Finding "big" form end:    1