3 - 41 3 - 41
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
(2) Finding the length of a character string
The LEN function is used to find the length of a character string.
10 A$ = "ABCDE"
20 A= LEN (A$)
30 PRINT A
40 END
RUN
5
OK
(3) Converting characters to ASCII code equivalents
Each character used in BASIC has a corresponding ASCII code number.
(See Appendix 4.1)
For example, for alphabet characters, the codes correspond as follows:
[Character]
[Code]
A
65
B
66
:
:
The ASC function and CHR$ function are used for conversion between ASCII
codes and characters.
Example
OK
PRINT ASC( " A" )
65
OK
PRINT CHR$(65)
A
OK
"A"
ASC
CHR$
65
Character
Value
• Only character constants, character arrays, or character conversion can be specified
inside the parentheses of an ASC function.
Only numeric constants, numeric arrays, or variables can be specified inside
the parentheses of a CHR$ function.
• Specifying number 31 or less in the parentheses in a CHR$ function will produce
control characters described in Section 3.13.1.
• Full-byte characters cannot be used with the ASC function.