beautypg.com

Rpbasic-52 programming guide – Remote Processing BASIC 52 User Manual

Page 22

background image

RPBASIC-52 PROGRAMMING GUIDE

2-3

ASC

Syntax:

A S C (ASCII character)
A S C (string,position expr)
Where: ASCII character = number from 0 to 255

string = any valid string v ariable
position expr = 1 to length of string

Function:

Returns or sets the integer value of an ASCII character or the character in string at position expr.

Mode:

Comm and, run

Use:

PRINT ASC (C)
ASC($(3),1)=48H
C = ASC($(0),P)

Cards:

All

D E S C R IP T I ON

The ASC operator either sets or returns the value of an ASCII character. Use ASC to evaluate, change or
manipulate individual characters in a string.

The first syntax retu rns the value of an ASC II character. If ASCII character were the letter 'B ', a 66 is
returned. Basic converts any lower case variable symbols to upper case. Lower case characters must be put
into a string to be evaluated.

The second syntax, shown under Use, sets a character in a string to a specific value. This is useful when you
want to manipulate individual characters in a string.

The third syntax returns a value in string at position expr. This form is usefu l when you want to eva luate
i nd iv id u al ch a ra c te r s i n a s tr in g , s u ch a s g e ne r at in g a c h ec k su m .

The STR comma nd, unique to RPBA SIC-52, manipulates entire strings.

RELATED

C H R , S T R , S T R I N G

E R R O R

S Y N T A X

Attempt to convert an improper value.

EXAMPLE

The following example prints ASCII values from the string $(0). The first 3 characters are modified at lines
70 to 90. The result is then printed.

10 STRING 200,20
20 $(0)="abc123"
30 FOR N=1 TO 6
40 PRINT ASC($(0),N),
50 NEXT
60 PRINT
70 FOR N=1 TO 3
80 ASC($(0),N)=65+N
90 NEXT
100 PRINT $(0)

READY
>RUN
97 98 99 49 50 51
BCD123