Help for this page

Select Code to Download


  1. or download this
    $txt = "This is a string";
    $count = $txt =~ tr/ //; #counts all spaces
    $count = () = $txt =~ m/\s/g;   #counts all whitespace characters
    $count = () = $txt =~ m/\s+/g;  #counts whitespace occurences (default
    + [split] behavior)
    
  2. or download this
    $count = tr/ // for ($txt);