Instr/InstrRev: Difference between revisions
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
''This function is for BASIC compatibility. It is not available in pure JavaScript projects.'' | |||
Instr([''start'', ]''string1'', ''string2''[, ''compare'']) | Instr([''start'', ]''string1'', ''string2''[, ''compare'']) | ||
Line 9: | Line 11: | ||
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 | 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 1 being the location of the first character, otherwise 0 is returned if ''string2'' is not found in ''string1''. | ||
'''Table: Comparison constants''' | |||
{| class="wikitable" | |||
|- | |||
! Constant !! Value !! Description | |||
|- | |||
| vbBinaryCompare || 0 || Binary comparison case sensitive (default) | |||
|- | |||
| vbTextCompare || 1 || Textual comparison, case insensitive | |||
|} | |||
== Example == | == Example (Basic) == | ||
<pre> | <pre> | ||
Line 26: | Line 39: | ||
<pre> | <pre> | ||
Finding "man" from start: 5 | Finding "man" from start: 5 | ||
Finding "big" | Finding "big" from end: 1 | ||
</pre> | </pre> | ||
Line 32: | Line 45: | ||
[[Category:Strings]] | [[Category:Strings]] | ||
[[Category:BASIC Functions]] |
Latest revision as of 15:27, 25 March 2019
This function is for BASIC compatibility. It is not available in pure JavaScript projects.
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 1 being the location of the first character, otherwise 0 is returned if string2 is not found in string1.
Table: Comparison constants
Constant | Value | Description |
---|---|---|
vbBinaryCompare | 0 | Binary comparison case sensitive (default) |
vbTextCompare | 1 | Textual comparison, case insensitive |
Example (Basic)
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" from end: 1