How to manipulate positional string elements.
This is primarily for things like object's material which is stored as a delimited string like this "player|living|hungry|fast".
The format of the delimited string for materials MUST be delimied by pipes ( vertical bars | ) and must not have leading or trailing delimiters.
These cowScript statements allow manipulation of these, however they can work with any delimited string.
In fact the pipes are converted to commas before manipulations so you can not use commas in the string you store.. maybe I should change this?
Now lets get started.
Finding what position a specific string is at:
$variable =|to position of {singlestring} at|from {delmitedstring} [ by {delimiter}];
Some examples:
$mymat = 'living|creature|roaming|sleepy';
$mm = position of "creature" in $mymat;
rem - $mm = 2;
$mm = position of living from $mymat by |;
rem - $mm = 1;
$wrd = 'mouse';
$mm = position of $wrd in $mymat;
rem - $mm = 0;
The variable you specify is set to the number reflecting the strings position. This has to be an exact match otherwise a 0 is returned being nothing found.
Reading a string from a specific position:
$variable =|to value at|of {number} in|from {delmitedstring} [ by {delimiter}];
Some examples:
$mymat = 'living|creature|roaming|sleepy';
$mm = value at 3 from $mymat;
rem - $mm = 'roaming';
$mm = value at 1 from $mymat by |;
rem - $mm = 'living';
$num = 7;
$mm = value at $num from $mymat;
rem - $mm = '';
The variable you set becomes the string from the position or '' if you specified a numbergreater than the items in the string.
Putting a string into a specific position:
$newstring =|to put|place {string} at position {number} in {delimitedstring} [ by {delimiter}];
Some examples:
$mymat = 'living|creature|roaming|sleepy';
$tx = 'mouse';
$nm = 3;
$mymat = put $tx as position $nm in $mymat;
rem - $mymat = 'living|creature|mouse|sleepy';
$fig = put 'dot' at position 7 in $mymat;
rem - $mymat = 'living|creature|mouse|sleepy||dot';
If you specify a number higher than the number of items in the list.. that many blanks wil be added.
Other variables:
Since the global @list is used for these, you have access to the same variables you get when manipulating lists.
read the coding manual and check out load, foreach and loop. Two fun variables from any @list are: $randomitem = a randome item from the list
$list_count = how many items in the list
$tmp = value at position 0 from 'one|two|three|four';
print "there are $list_count items and I choose $randomitem";
When putting a value into a position there is a $rawstring variable which is identical to the final string however it has commas instead of the delimiter you specified or pipes by default.
PS $rawstring is also avaiable after using swap add/take