Site Tools


left

# $EPIC: left.txt,v 1.4 2006/08/01 04:12:59 sthalik Exp $

Synopsis:

$left(<count> <text>)

Technical:

  • If <count> is omitted, this function returns the empty string.
  • If <text> is omitted, this function returns the empty string.
  • If <count> is less than 0, this function returns the empty string.
  • If <text> is more than <count> characters long, then this function will return a copy of the first <count> characters in <text>.
  • If <text> is less than or exactly <count> characters long, then this function will return a copy of <text>

Practical:

Whenever you need to extract the initial part of a string, you would use this function to get it. This is more useful for fixed-format strings. ircII used to use $left($index(<char> <text>) <text>) to extract the part of <text> that was before <char>. In EPIC, use $before(<char> <text>) because it is faster, more clear, and doesn't require two copies of <text>, which may be important if <text> is a function call.

Returns:

The first <count> characters in <text>. No padding is done. If you need a string that is always <count> characters long, try:

$pad(<count> " " $left(<count> <text>))

Examples:

$left(5 biklmnopstv)                     returns "biklm"
$left(15 biklmnopstv)                    returns "biklmnopstv"
$left(-2 biklmnopstv)                    returns nothing
$left($index(@ $userhost()) $userhost()) returns a username in an /on.
  -- Note that this construction is obsolete, but is still used by some.

History:

This function first appeared in ircII.

left.txt · Last modified: 2006/08/01 04:13 by 127.0.0.1