String Handling Routines: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
atNgaovBCTIdyC
 
(70 intermediate revisions by 37 users not shown)
Line 1: Line 1:
comment3
{{TOCright}}
==Simple==
{{Flink|string|to_lower_case|string|desc=Converts all upper-case alphabetic characters to lower-case.}}
{{Flink|string|to_upper_case|string|desc=Converts all lower-case alphabetic characters to upper-case.}}
{{Flink|string|to_url|location|desc=Returns the url which is accessed to visit the specified location.}}
{{Flink|int|extract_meat|string|desc=Returns the number of meat embedded in a string.}}
{{Flink|int [item]|extract_items|desc=Parses a string for items and their amounts (handles plural & singular forms) and returns the results as a map.}}
{{Flink|int|length|string|desc=Returns the number of characters in the specified string.}}
{{Flink|string|char_at|string|index|desc=Returns the character at a specified index in a string.}}
{{Flink|string|substring|string|int|{{opt|int}}|desc=Returns the substring of the specified string, starting from a specified position, and optionally ending before a specified position (defaults to remainder of string).}}
{{Flink|buffer|replace_string|buffer|string|string}}
{{Flink|buffer|replace_string|string|string|string|desc=Replaces all text in the first string that matches the second with the third.}}
{{Flink|buffer|replace|buffer|int|int|string|desc=Replaces all text from the first index to the second index with the supplied string.}}
{{Flink|string|url_encode|string|desc=Converts a string into a URL formatted string.}}
{{Flink|string|url_decode|string|desc=Converts a URL formatted string into regular text.}}
{{Flink|string [int]|split_string|string|{{opt|string}}|desc=Splits apart the first string at line-breaks or using an optionally supplied delimeter and returns an integer-keyed map of the result.}}
{{Flink|string [int]|session_logs|{{opt|string}}|int|desc=Gives access to sessions logs. And stuff. [http://kolmafia.us/showthread.php?t=573]}}
{{Flink|buffer|append|buffer|string|desc=Appends the string to the end of the buffer.}}
{{Flink|void|set_length|buffer|int|desc=Changes the length of a buffer.}}
{{Flink|buffer|delete|buffer|int|int|desc=Deletes the specified portion of the buffer.}}
{{Flink|buffer|insert|buffer|int|string|desc=Inserts the string at the specified point in the buffer.}}
==Substring Search==
{{FunctionEmbed|contains_text|format=signature|desc=yes}}
{{FunctionEmbed|ends_with|format=signature|desc=yes}}
{{FunctionEmbed|index_of|format=signature|desc=yes}}
{{FunctionEmbed|last_index_of|format=signature|desc=yes}}
{{FunctionEmbed|starts_with|format=signature|desc=yes}}
 
==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.
 
{{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|int|group_count|matcher|desc=Returns the number of capturing groups in the pattern.}}
{{Flink|string [int,int]|group_string|string|string|desc=Maps a string to an aggregate (see page for details). [http://kolmafia.us/showthread.php?t=318]}}
{{Flink|int|start|matcher|{{opt|int}}|desc=Returns the starting index of the previous or specified capturing group.}}
{{Flink|int|end|matcher|{{opt|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|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|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|buffer|append_replacement|matcher|buffer|string}}
{{Flink|buffer|append_tail|matcher|buffer|desc=Appends the text returned by a matcher to the end of the buffer.}}
 
[[Category:Scripting]]

Latest revision as of 12:43, 23 December 2020

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 to_url( location )

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

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.

string char_at( string, index )

Returns the character at a specified index in a string.

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.

buffer replace( buffer, int, int, string )

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

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] session_logs( [string], int )

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

buffer append( buffer, string )

Appends the string to the end of the buffer.

void set_length( buffer, int )

Changes the length of a buffer.

buffer delete( buffer, int, int )

Deletes the specified portion of the buffer.

buffer insert( buffer, int, string )

Inserts the string at the specified point in the buffer.

Substring Search

boolean contains_textstring, string )

Returns true if the first string contains the second string.

boolean ends_withstring, string )

Checks whether a string ends with a suffix string. (case-sensitive)

int index_ofstring, 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_ofstring, string, int? )

Returns the last index of the second string in the first, or -1 if no match is found.

boolean starts_withstring, string )

Checks whether a string starts with a prefix string. (case-sensitive)

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.

matcher create_matcher( string, string )

Creates a matcher from a pattern and input string.

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.

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

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

int start( matcher, [int] )

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

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, [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.