$char

By LIQUID_NiTrO on Feb 20, 2005

Syntax: $char(text,N)
Syntax: /char text N
simply returns Nth character in text, counting from the left. There might be a builtin identifier for this but I looked and looked and couldn't find one so I made my own. It's got a bit of poor coding in that the local variable %f is pretty unclean, but its functional.

alias char {
  if ( !$1 ) || ( !$2 ) || ( $2 !isnum 1- ) {
    $iif($isid == $false,echo $colour(info) -a * CHAR not enough parameters,return $null)
  }
  if ( $2 > $len($1) ) {
    $iif($isid == $false,echo $colour(info) -a * CHAR $2 $+ th character does not exist,return $null)
    halt
  }
  var %x = 1,%f = 0
  while ( %x <= $2 ) {
    %f = $addtok(%f,$remove($left($1,%x),$left($1,$calc(%x - 1))),44)
    inc %x 1
  }
  $iif($isid == $false,echo $colour(info) -a * CHAR: $gettok(%f,$numtok(%f,44),44),return $gettok(%f,$numtok(%f,44),44))
}

Comments

Sign in to comment.
LIQUID_NiTrO   -  May 07, 2005

$left(text,N) returns the Nth character AND all the characters preceeding it, making it different from this identifier or $mid

 Respond  
Aether   -  Mar 26, 2005

$left...

 Respond  
Pikachuh   -  Feb 22, 2005

Can u add an asc inmediatly :)

 Respond  
Yoinx   -  Feb 21, 2005

actually, more diverse you can use $mid(testtext,4,3) to get tte or $mid(testtext,4,1) to get t ;p

 Respond  
LIQUID_NiTrO   -  Feb 21, 2005

grrh. I stand corrected.

 Respond  
RusselB   -  Feb 20, 2005

Another way of doing that is to use $mid(string,count,1)

 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.