11 - 96 11 - 96
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
INSTR Function
IN STRing
• Searches a specified character string in the character string and returns the position of the
first match.
INSTR ([ <numeric expression > ,] <character string expression 1>, < character string
expression 2> )
numeric expression
• • • •
Specify the position to start searching the character
string.
character string expression 1
• • • •
Specify the target character string.
Syntax
character string expression 2
• • • •
Specify the character string to be searched.
A=INSTR(2, A$, “ABC”)
• • • •
Searches the character string “ABC” from the second
character of A$, and assigns the position if found or
assigns 0 if not found to A.
Examples
A$
1 2 3 4 A B C D E
1 2 3 4 5 6 7 8 9 10
A$
A B 1 2 3 4 C D E F
A
A
5
0
F
Search area
Description
• The INSTR function searches <character string expression 2> in <character string
expression 1>, then returns the position of the first match if found or returns 0 if not found.
• Specify the position to start the search to <numeric expression>. If omitted, the search
starts from the beginning of <character string expression 1>, and the INSTR function
returns 0 if a value larger than the number of characters in <character string expression 1>
is specified.
• 0 is returns if <character string expression 1> is an empty character string.
• The same value as <numeric expression> is returned if <character string expression 2> is
an empty character string.
• The INSTR function processes a full-byte character as two half-byte characters. See the
KINSTR function for searching a full-byte character as one character.
A$
A B
@
@
C D
A$
8
6
INSTR(A$, "D" )
KINSTR(A$, "D" )
1 2 3 4 5 6 7 8
1 2
3
4
5 6
A B
@
@
C D