$lists - Returns items in list fashion.

By Scakk on Sep 17, 2008

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) }
  }
}

Comments

Sign in to comment.
Scakk   -  Sep 17, 2008

Update: 17Sep08 Fixed the issue if $2 is below 0 or above 256.

Thanks napalm.

 Respond  
napalm`   -  Sep 17, 2008

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
}
 Respond  
EL   -  Sep 17, 2008

Heh looks good scakk from the version i tested.`-.-´

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.