Length: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>PhilmASTErpLus
Added code sample and removed needscode=yes|
imported>Bale
remove_spaces( ) is only 1 line long. Nice example though.
 
Line 21: Line 21:
description=The following example determines the number of characters in the name of a hat.|
description=The following example determines the number of characters in the name of a hat.|
code=<syntaxhighlight>
code=<syntaxhighlight>
/* Assume string remove_spaces( item ) exists */
item the_hat = $item[ pail ];
item the_hat = $item[ pail ];
string parsed_name = remove_spaces( the_hat );
// First we need to remove all spaces with replace_string()
string parsed_name = replace_string( the_hat, " ", "" );
if ( item_type( the_hat ) == "hat" && length( parsed_name ) == 4 )
if ( item_type( the_hat ) == "hat" && length( parsed_name ) == 4 )
   print( "You can receive the +20ML buff from the Mad Tea Party." );
   print( "You can receive the +20ML buff from the Mad Tea Party." );

Latest revision as of 09:02, 26 June 2010

Function Syntax

int length(string count_me )

  • count_me is the string to check

Returns the number of characters (not 0-indexed) in a string. Note that for escaped characters, only the actual character &#151; not the escape marker &#151; is counted.

Code Sample

The following example determines the number of characters in the name of a hat.

item the_hat = $item[ pail ];
// First we need to remove all spaces with replace_string()
string parsed_name = replace_string( the_hat, " ", "" );
if ( item_type( the_hat ) == "hat" && length( parsed_name ) == 4 )
   print( "You can receive the +20ML buff from the Mad Tea Party." );

Note that you can easily receive Mad Tea Party buffs by using the hatter CLI command or the hatter.ash script.