String Handling Routines: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Heeheehee
imported>Bale
fixes
Line 25: Line 25:
==Regular Expressions==
==Regular Expressions==
{{Flink|matcher|create_matcher|string|string|desc=Creates a matcher from a pattern and input string.}}
{{Flink|matcher|create_matcher|string|string|desc=Creates a matcher from a pattern and input string.}}
{{Flink|matcher|reset|matcher|{{opt|string}}|desc=Resets matcher to search from beginning of string, possibly with new input.}}
{{Flink|matcher|reset|matcher}}
{{Flink|matcher|reset|matcher|string|desc=Resets matcher to search from beginning of string, possibly with new input.}}
{{Flink|int|group_count|matcher|desc=Returns the number of capturing groups in the pattern.}}
{{Flink|int|group_count|matcher|desc=Returns the number of capturing groups in the pattern.}}
{{Flink|int|start|matcher|{{opt|int}}|desc=Returns the starting index of the previous or specified capturing group.}}
{{Flink|int|start|matcher}}
{{Flink|int|end|matcher|{{opt|int}}|desc=Returns the ending index of the previous or specified capturing group plus 1.}}
{{Flink|int|start|matcher|int|desc=Returns the starting index of the previous or specified capturing group.}}
{{Flink|int|end|matcher}}
{{Flink|int|end|matcher|int|desc=Returns the ending index of the previous or specified capturing group plus 1.}}
{{Flink|boolean|find|matcher|desc=Finds the next instance of the pattern or returns false if no more matches exist.}}
{{Flink|boolean|find|matcher|desc=Finds the next instance of the pattern or returns false if no more matches exist.}}
{{Flink|string|group|matcher|{{opt|int}}|desc=Returns the contents of an indicated capturing group (starting at 1) or the entire pattern if not indicated.}}
{{Flink|string|group|matcher}}
{{Flink|string|group|matcher|int|desc=Returns the contents of an indicated capturing group (starting at 1) or the entire pattern if not indicated.}}
{{Flink|string|replace_all|matcher|string|desc=Replaces all pattern matches with a given string.}}
{{Flink|string|replace_all|matcher|string|desc=Replaces all pattern matches with a given string.}}
{{Flink|string|replace_first|matcher|string|desc=Replaces the first pattern match with a given string.}}
{{Flink|string|replace_first|matcher|string|desc=Replaces the first pattern match with a given string.}}

Revision as of 06:56, 5 May 2010

Simple

string to_lower_case( string )

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

string to_upper_case( string )

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

string today_to_string()

Returns the current day in ISO format (based on your computer's settings).

string visit_url( string )

Visits the specified address and returns the page source (see page for details).

string to_url( location )

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

boolean contains_text( string, string )

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

int extract_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.

int length( string )

Returns the number of characters in the specified string.

int index_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.

int last_index_of( string, string )

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

string substring( 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).

buffer replace_string( buffer, string, string )

buffer replace_string( string, string, string )

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

string url_encode( string )

Converts a string into a URL formatted string.

string url_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,int] group_string( string, string )

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

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

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

buffer append( buffer, string )

Appends the string to the end of the buffer.

buffer delete( buffer, int, string )

Deletes the specified portion of the buffer.

buffer insert( buffer, int, int )

Inserts the string at the specified point in the buffer.


Regular Expressions

matcher create_matcher( string, string )

Creates a matcher from a pattern and input string.

matcher reset( matcher )

matcher reset( matcher, string )

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

int group_count( matcher )

Returns the number of capturing groups in the pattern.

int start( matcher )

int start( matcher, int )

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

int end( matcher )

int end( matcher, int )

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

boolean find( matcher )

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

string group( matcher )

string group( matcher, int )

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

string replace_all( matcher, string )

Replaces all pattern matches with a given string.

string replace_first( matcher, string )

Replaces the first pattern match with a given string.

buffer append_replacement( matcher, buffer, string )

buffer append_tail( matcher, buffer )

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


Attention KoLmafia Experts!

We need your help; some details of this function's operation are unknown or unclear.

The following specific questions have been raised:

  • Argh, anyone comfortable with regex who wants to fill in the blanks?
  • Please? (Feel free to ignore formatting and just describe what happens)