"abcdefg"*2returns abcdefgabcdefg (two times the string)
"abcdefg"*-1returns gfedcba (the string is inversed)
"abcdefg"*1.5returns abcdefgabc

Transforming a string with trailing modifers

If you follow a string expression a$ by brackets containing a modifier list in the format:

a$ [modifierlist]

you can transform the string in several useful ways. The modifierlist can be any of the following characters:

+convert lower case letters to upper case
-convert upper case letters to lower case
<strip leading spaces (and control characters)
>strip trailing spaces (and control characters)
~strip bit 7 (More about bit 7 in Chapter 23) terminator from last character of string
^add bit 7 terminator to last character of string
(f$,r$)replace any occurrences of characters present in f$ with the corresponding character from r$ (or delete if there is no corresponding character)

The order of the modifiers is unimportant, except for (f$,r$) which, if present, must be the final modifier.

The following examples demonstrate what can ne achieved:

"   Hello There!   "[<+->]"

gives: hELLO tHERE!

as trailing and leading spaces are stripped via < and >and all lower case letters are converted to upper case with the + and upper case to lower case with the -.

"My typewriter is broken"[("nore","dro")]

returns My typwoito is borkd as r$ doesn't have a corresponding letter for the e of f$ so all of them are deleted, all o are replaced by r and all r are replaced by o

Note that it is possible to slice a modified string, or modify a sliced string, since both () and [] continue to be evaluated following a string argument until there are no further opening parentheses or brackets. For example:

a$(5)[-](3 TO 7)[<]

is perfectly valid.

Tokenisation of strings

If need be, (for example to easily prepare strings to be passed to functions VAL or VAL$ – See next Chapter) we can tokenise, that is to convert NextBASIC reserved words to their single code equivalents (tokens) – without syntax checking– the contents of a string expression a$ by enclosing it in braces {} like so:

{a$}

For example:

{"sin (pi/4)"}returns a string "SIN (PI/4)", including
the tokens SIN (code 178) and PI (code 167)
VAL{"sin (pi/4)"}gives 0.7071

ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.