beautypg.com

Remote Processing CAMBASIC User Manual

Page 111

background image

Comm ands - 78

MID$

String Statement

SYNTAX:

MID$( a$,s [, n]) = b$

PURPOSE:

To replace a portion of one string with another.

REMARK S:

A common usage for the MID$ statement is in networking protocols. The network commands are
standard strings defined by string variables.

Using the M ID$ statemen t to modify these strings is much faster than other str ing methods.

The string a$ is the target string, while b$ is the replacement string.

The parameter s is the starting point within a$ where b$ will be inserted. The optional parameter n
indicates how many characters of b$ are to be used. W hen n is omitted, all of b$ is used.

If b$ is longer than a$, replacem ent will not exceed the length of a$. N o error m essage will be
given.

RELATED:

LEF T$, LEN , RIG HT$, INSTR, MID$ F unction

EXAMPLE:

10 F$ = "Hopeless"
20 R$ = "Help"
30 MID$(F$,1) = R$
40 PRINT F$

Helpless

The exa mple belo w is for a comm unications pr otocol. Note that the escape cha racter is not a
printable character.

10 CV$=CHR(27) + "A" + "12"
20 MID$(CV$,3) = "23"
30 PRINT CV$
ESC A23

ERROR:

< Data negative> – for s and n
< Data out of range> – if s = 0
< Data > 255> – for s and n