This identifier will return a group of words in a list fashion.
Usage: $lists(TEXT,C)
Ex: //echo -ag $lists(red tree grows,32) ----> red, tree, grows
Ex: //echo -ag $lists(red tree grows,32).a --> red, tree, and grows
Ex: //echo -ag $lists(red tree grows,32).c --> Red, tree, grows
Ex: //echo -ag $lists(red tree grows,32).ac -> Red, tree, and grows
Update: 17Sep08 Fixed the issue if $2 is below 0 or above 256.
/*
Usage: $lists(TEXT,C)
Ex: //echo -ag $lists(red tree grows,32) ----> red, tree, grows
Ex: //echo -ag $lists(red tree grows,32).a --> red, tree, and grows
Ex: //echo -ag $lists(red tree grows,32).c --> Red, tree, grows
Ex: //echo -ag $lists(red tree grows,32).ac -> Red, tree, and grows
*/
alias lists {
if ($isid && $1 && $2 isnum 1-256) {
if (!$istok(a c ac ca,$prop,32)) { return $replace($1,$chr($2),$+($chr(44),$chr(32))) }
if ($prop == a) { return $instok($replace($1,$chr($2),$+($chr(44),$chr(32))),and,-1,32) }
if ($prop == c) { return $replace($+($upper($left($1,1)),$right($1,-1)),$chr($2),$+($chr(44),$chr(32))) }
if ($istok(ac ca,$prop,32)) { return $instok($replace($+($upper($left($1,1)),$right($1,-1)),$chr($2),$+($chr(44),$chr(32))),and,-1,32) }
}
}
Your code does not work when $2 is less than one or greater than 255.
alias list {
if ($2 !isnum) || (0 > $2 || $2 > 255) || (!$isid) return
var %a $regsubex($$1,/ $+ $chr($2) $+ /gi,$+($chr(44),$chr(32)))
if ($regex($prop,^(a|c)(a|c)?$)) {
if (a isin $prop) %a = $instok(%a,and,-1,32)
if (c isin $prop) %a = $upper($left(%a,1-)) $+ $right(%a,-1)
}
return %a
}