Difference between revisions of "$len"

From Scriptwiki
Jump to: navigation, search
 
m (fixed grammar)
Line 5: Line 5:
 
$len(length) returns 6.
 
$len(length) returns 6.
  
$len() is simple, but powerful tool processing strings.
+
$len() is simple, but powerful tool for processing strings.
  
 
== Examples ==
 
== Examples ==
  
This example turn uppercase letters to lowercase and upwards.
+
This example turns uppercase letters to lowercase and vice-versa.
<br/>$len is used to get value of string (value given to alias) and loop through it every character.
+
<br/>$len is used to get the length of the string (the value given to the alias) and loop through its every character.
  
 
  [[Aliases|alias]] changecase {
 
  [[Aliases|alias]] changecase {
Line 17: Line 17:
 
     %c = [[$mid]]($1-, %i, 1)
 
     %c = [[$mid]]($1-, %i, 1)
 
     [[If-Then-Else|if]] ([[$isupper]](%c)) {
 
     [[If-Then-Else|if]] ([[$isupper]](%c)) {
       %str = %str [[$+]] [[$lower]](%c)
+
       %str = %str [[DollarPlus|$+]] [[$lower]](%c)
 
     }
 
     }
 
     [[If-Then-Else|else]] {
 
     [[If-Then-Else|else]] {

Revision as of 14:38, 10 November 2005

Returns the length of text.

$len(text)

$len(length) returns 6.

$len() is 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