$len

From Scriptwiki
Revision as of 20:00, 24 August 2005 by Tovrleaf (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Returns the length of text.

$len(text)

$len(length) returns 6.

$len() is simple, but powerful tool processing strings.

Examples

This example turn uppercase letters to lowercase and upwards.
$len is used to get value of string (value given to alias) and loop through it every character.

alias changecase {
  var %i = 1, %str, %c
  while (%i <= $len($$1-)) {
    %c = $mid($1-, %i, 1)
    if ($isupper(%c)) {
      %str = %str $+ $lower(%c)
    }
    else {
      %str = %str $+ $upper(%c)
    }
    inc %i
  }
  return %str
}

echo -a $changecase(Hello)
; returns hELLO