11 - 144 11 - 144
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
MID$ (Part 2)
Function
MIDdle $
• Returns the partial character expression that begins with the specified position in a
character string.
MID$( <character string expression> , <integer expression 1> [, <integer expression 2> ] )
character string expression 1
• • • •
Specify the source character string or character
string variable.
integer expression 1
• • • •
Specify the starting position of the character string
that will be extracted.
Syntax
integer expression 2
• • • •
Specify the number of characters of the character
string that will be extracted.
A$=MID$(B$,3,2)
• • • •
Extracts the third and fourth character from the left of
character string B$ and stores it in A$.
Examples
B$= "NAGOYA"
B$
A$
N A G O Y A
G O
Description
• The MID$ (part 2) function extracts a character string from the specified position in a
character string.
• If <integer expression 2> is omitted, or if the remaining number of characters of the position
specified by <integer expression 1> is less than the number of characters specified by
<integer expression 2>, the remainder of the character string from the position specified
by <integer expression 1> will be returned.
• If the value of <integer expression 1> is greater than the length of <character string
expression>, an empty character string will be returned.
Program Example
10 ' Extracts character string
20 A$="AD51H-BASIC"
:
' Defines character string
40 B$=MID$(A$,7,5)
:
' Extracts 5 characters from the 7th
character in the character string
50 PRINT "Extracted characters-->";B$
60 END
RUN
Extracted characters-->BASIC
OK
REMARK
See the RIGHT$, LEFT$ and MID$ (Part 1) functions, and Section 3.13.