From Scriptwiki
Revision as of 19:00, 25 April 2008 by Daveoh (talk | contribs)

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

Returns the length of a string, i.e. how many characters are within it.


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


$len(test string) returns 11.

The following 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

See Also

  • $mid - returns parts of a string
  • $str - repeats a string