String Function - Sharp MZ-700 Series Owner's Manual

Personal computer
Hide thumbs Also See for MZ-700 Series:
Table of Contents

Advertisement

5 String Function
>.1 LEN
Format
Function
Example
LEN (XS)
X$ . . . String expression
This funcion returns the number of characters included in the string expression
represented by X$. This value includes spaces which are not displayed on the screen
and any control characters in the string, as well as letters, numefals, and symbols.
(Example 1)
1 0
A $ =
1 1
A B C D E F G "
2 0
P R I N T
L E N
( A $ >
R U N
7
(Example 2) The following program uses the LEN funcition to draw squares on the
screen.
1 0
9 " E " : 9 " E N T E R
3 0 R
M O R E
A S T E R I S K S "
2 0
I N P U T
A S
3 0
F O R
I = 1
T O
L E N ( A S )
- 2
4 0
P R I N T
T A B ( 2 )
; " * " ; S P C ( L E N ( A S ) - 2 )
; " ' * "
5 0
N E X T
I
6 0
P R I N T
T A B ( 2 )
; A S : G O T O
2 0
(Example 3) The LEN function can also be used to produce a "parade" of charac-
ters as shown below.
1 0
S $ = " S H A R P
B A S I C "
2 0
F O R
1 = 1
T O
L E N
( S S )
3 0
9
R I G H T S ( S S ,
I )
4 0
N E X T
I
5 0
E N D
R U N
C
I C
S I C
S H A R P
B A S I C
(Example 4)
P R I N T
L E N ( S T R S ( P A I ( 1 ) ) ) J
9
PAI (1), the function which returns the value of the ratio of the circumference of a
circle to its diameter, contains the 8-digit constant 3.1415927 (approximately the
value of PI). When the length of the character string produced by converting this
constant with the STR$ function is evaluated with the LEN function, a total string
length of 9 is returned.

Advertisement

Table of Contents
loading

Table of Contents