$len: Difference between revisions

From Scriptwiki
Jump to navigation Jump to search
m fixed grammar
m small changes
Line 1: Line 1:
Returns the length of text.
Returns the length of a piece of text, i.e. the number of characters in it.


  $len(text)
  $len(text)


$len(length) returns 6.
$len(test string) returns 11.


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


== Examples ==
== Examples ==

Revision as of 13:50, 10 November 2005

Returns the length of a piece of text, i.e. the number of characters in it.

$len(text)

$len(test string) returns 11.

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

Examples

This example turns uppercase letters to lowercase and vice-versa.
$len is used to get the length of the string (the value given to the alias) and loop through its 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