Yarn is a library which provides various string processing functions. All functions return new strings and will not taint the inputs.
Instructions:
SPLIT$(string$,separator$)
Splits
string$ into substrings at each occurrence of
separator$ and returns a new string array containing every substring (including empty ones.) If
separator$ is the empty string, the output array is the list of every character in the string. Commonly used with
JOIN$().
DIM OUT$[0]
OUT$=SPLIT$("HELLO WORLD"," ")
FOR I%=0 TO LEN(OUT$)-1
PRINT OUT$[I%]
NEXT
This is a function which returns an array, which usually isn't standard practice in SB. Use carefully.
JOIN$(array$[],separator$)
Returns a new string by joining all of the entries in
array$[] together, with
separator$ placed between them. Commonly used with
SPLIT$().
DIM IN$[3]
COPY IN$,@FRUIT
PRINT JOIN$(IN$,",") 'APPLE,BANANA,ORANGE
@FRUIT
DATA "APPLE","BANANA","ORANGE"
REPLACE$(string$,old$,new$)
Returns a new version of
string$ where all occurrences of
old$ are replaced with
new$.
PRINT REPLACE$("HELLO WORLD","L","Q") 'HEQQO WORQD
COUNT(string$,substring$)
Returns the number of times
substring$ occurs in
string$, as an integer.
PRINT COUNT("AABAA","A") '4
UPPER$(string$)
Returns a new version of
string$ where every lowercase letter is uppercase. Does not touch any other characters. Supports most (if not all) alphabets in SB's character set.
PRINT UPPER$("Hello wORLD") 'HELLO WORLD
LOWER$(string$)
Returns a new version of
string$ where every uppercase letter is lowercase. Does not touch any other characters. Supports most (if not all) alphabets in SB's character set.
PRINT LOWER$("Hello wORLD") 'hello world
REVERSE$(string$)
Returns a backwards version of
string$.
PRINT REVERSE$("HELLO WORLD") 'DLROW OLLEH
TRIM$(string$)
Returns a version of
string$ with leading and trailing whitespace removed. Whitespace characters are tab, space, linefeed, and carriage return.
PRINT TRIM$(" A ") 'A
REST$(string$,start%)
Returns the rest of
string$ starting at
start%. In other words, returns a substring of
string$ which starts at
start% and runs to the end of the string.
PRINT REST$("HELLO WORLD",6) 'WORLD