Swap
Use swap to change text within a string variable.
Swap has 2 ways of working on a string:
Syntax 1: swap $variable add|take {string} [by {delimiter}];
Syntax 2: swap $variable so {oldstring} is {newstring};
{string} in this context is iether a string with or without quotes or a $variable that contains a string eg $actor's colour;
x is a delimiter character (or characters) and the default is a pipe or vertical bar |
If your added string contain iether a comma or your designated delimiter then you will be inserting multiple entities.
When doing the manipulations, all delimiters are converted to commas for simplicity then reverted back to your designated or default delimiter.
Using the first variety with iether 'add' or 'take' the string from the variable.
- If the string already exists it will not be added twice.
- Newly added strings are added to the end.
- No leading or trailing delimiters are left in your string however they are temorarily added so you can manipluate the first and last entities without fear.
eg:
$rrr = "_roaming_";
$mat = "_living_|_roaming_|_dancing_";
swap $mat add _sleeping_;
swap $mat add _living_;
swap $mat take $rrr;
rem $mat will be '_dancing_|_sleeping_|_living_';
Using swap to replace one string with another, is not as complicated and pays no attention to delimiters:
$mat = "we talk about talking";
swap $mat so "talk" is "sing";
rem $mat will be 'we sing about singing";
- replacing a sring does not do any delimiter cleanup
- you can replace a string with a blank string
- this uses perl regular expressions and escape characters so you could do these strange things:
swap $mat so "\\|\\|" is "\\|"; rem - remove duplicate pipe dleimiters;
swap $mat so "^" is "now";
swap $map so "$" is "quietly";
rem $mat = 'now we sing about singing quietly';
read the info about material manipulation
read the info about value of