String Handling Routines

From KoLMafia
Jump to: navigation, search

Simple

stringto_lower_case( string )

Converts all upper-case alphabetic characters to lower-case.

stringto_upper_case( string )

Converts all lower-case alphabetic characters to upper-case.

stringto_url( location )

Returns the url which is accessed to visit the specified location.

booleancontains_text( string, string )

Returns true if the second string is found as a substring of the first.

intextract_meat( string )

Returns the number of meat embedded in a string.

int [item] extract_items()

Parses a string for items and their amounts (handles plural & singular forms) and returns the results as a map.

intlength( string )

Returns the number of characters in the specified string.

stringchar_at( string, index )

Returns the character at a specified index in a string.

intindex_of( string, string, [int] )

Returns the position of the second string in the first (or -1 if not found), optionally starting its search from a given position.

intlast_index_of( string, string )

Returns the last index of the second string in the first.

stringsubstring( string, int, [int] )

Returns the substring of the specified string, starting from a specified position, and optionally ending before a specified position (defaults to remainder of string).

bufferreplace_string( buffer, string, string )

bufferreplace_string( string, string, string )

Replaces all text in the first string that matches the second with the third.

bufferreplace( buffer, int, int, string )

Replaces all text from the first index to the second index with the supplied string.

stringurl_encode( string )

Converts a string into a URL formatted string.

stringurl_decode( string )

Converts a URL formatted string into regular text.

string [int]split_string( string, [string] )

Splits apart the first string at line-breaks or using an optionally supplied delimeter and returns an integer-keyed map of the result.

string [int]session_logs( [string], int )

Gives access to sessions logs. And stuff. [1]

bufferappend( buffer, string )

Appends the string to the end of the buffer.

voidset_length( buffer, int )

Changes the length of a buffer.

bufferdelete( buffer, int, int )

Deletes the specified portion of the buffer.

bufferinsert( buffer, int, string )

Inserts the string at the specified point in the buffer.


Regular Expressions

It is advised that anyone desiring to use these functions should first understand the basics of Regular Expressions and how these functions implement that language.


matchercreate_matcher( string, string )

Creates a matcher from a pattern and input string.

matcherreset( matcher, [string] )

Resets matcher to search from beginning of string, possibly with new input.

intgroup_count( matcher )

Returns the number of capturing groups in the pattern.

string [int,int]group_string( string, string )

Maps a string to an aggregate (see page for details). [2]

intstart( matcher, [int] )

Returns the starting index of the previous or specified capturing group.

intend( matcher, [int] )

Returns the ending index of the previous or specified capturing group plus 1.

booleanfind( matcher )

Finds the next instance of the pattern or returns false if no more matches exist.

stringgroup( matcher, [int] )

Returns the contents of an indicated capturing group (starting at 1) or the entire pattern if not indicated.

stringreplace_all( matcher, string )

Replaces all pattern matches with a given string.

stringreplace_first( matcher, string )

Replaces the first pattern match with a given string.

bufferappend_replacement( matcher, buffer, string )

bufferappend_tail( matcher, buffer )

Appends the text returned by a matcher to the end of the buffer.