String Handling Routines: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
imported>StDoodle
No edit summary
Line 1: Line 1:
== Part  8 - String Handling Routines ==
{{Flink||void|print|string|{{opt|string}}|desc=Prints the given string to the CLI and status line, optionally in the specified color.}}
<p><em>Under Construction</em></p>
{{Flink|string|visit_url|string|desc=Visits the specified address and returns the page source (see page for details).}}
<p><strong>void print( string helloworld )</strong><br>
{{Flink|string|location_to_url|location|desc=Returns the url which is accessed to visit the specified location.}}
Prints the given string to the graphical CLI window and to the status line of the main Adventuring window.</p>
{{Flink|boolean|contains_text|string|string|desc=Returns true if the second string is found as a substring of the first.}}
<p><strong>string [[visit_url alpha|visit_url( string url )]]</strong><br>
{{Flink|int|extract_meat|string|desc=Returns the number of meat embedded in a string.}}
Accesses the specified URL, manages any applicable redirects (including if the page offered a choice adventure), and returns the HTML of the final response page.</p>
{{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.}}
<p><strong>string location_to_url( location place )</strong><br>
{{Flink|int|length|string|desc=Returns the number of characters in the specified string.}}
 
{{Flink|int|index_off|string|string|{{opt|int}}|desc=Returns the position of the second string in the first (or -1 if not found), optionally starting from a given position.}}
Returns the URL that would need to be accessed to visit the specified location.</p>
{{Flink|int|last_index_of|string|string|desc=Returns the last index of the second string in the first.}}
<p><strong>boolean contains_text( string source, string query )</strong><br>
{{Flink|string|substring|string|int|{{opt|int}}|desc=Returns the substring of the specified string, starting from a specified position, and optionally ending at a specified position (defaults to remainder of string).}}
Reveals if the query string is a substring of the source string.</p>
{{Flink|string|replace_string|string|string|string|desc=Replaces all text in the first string that matches the second with the third.}}
<p><strong>int extract_meat( string text )</strong><br>
{{Flink|string|url_encode|string|desc=Converts a string into a URL formatted string.}}
Returns the amount of meat contained in a string passed to it in integer format. For use in k-mail parsing. *Not for use on pending trades.*</p>
{{Flink|string|url_decode|string|desc=Converts a URL formatted string into regular text.}}
<p><strong>int [item] extract_items( string text )</strong><br>
{{Flink|string [int]|split_string|string|{{opt|rstring}}|desc=Splits apart the first string at line-breaks or using an optionally supplied delimeter and returns an integer-keyed map of the result.}}
takes the text you have provided and parses it for any items that KoLmafia would have found normally.  This means you have access to the built-in pluralization handler as well as the ability to NOT have to lookup description IDs or whatever other loops you had to use to access that information. For use in k-mail parsing. *Not for use on pending trades.*</p>
{{Flink|string [int,int]|group_string|string|string|desc=This does... something regex-y. I dunno. [http://kolmafia.us/showthread.php?t=318]}}
<p><strong>int [[length]]( string text )</strong><br>
{{Flink|string [int]|session_logs|{{opt|string}}|int|desc=Gives access to sessions logs. And stuff. [http://kolmafia.us/showthread.php?t=573]}}
Returns the length of the given string.</p>
{{Flink|buffer|append|buffer|string|desc=Appends the string to the end of the buffer.}}
 
{{Flink|buffer|append_tail|matcher|buffer|desc=Appends the text returned by a matcher to the end of the buffer.}}
<p><strong>int index_of( string source, string search )</strong><br>
Returns the first index of a given substring in a string.<br>
<strong>int index_of( string source, string search, int start )</strong><br>
Returns the next index of a given substring in a string starting from the given position.<br>
<strong>int last_index_of( string source, string search )</strong><br>
Returns the last index of a given substring in a string.</p>
<p><strong>string substring( string source, int startfrom )</strong><br>
Returns the substring of the given string starting from the given character position in the string, and ending at the last character.<br>
<strong>string substring( string source, int start, int end )</strong><br>
 
Returns the substring of the given string starting from the character position indicated by start in the string, and ending at the character position indicated by end.</p>
<p><strong>string replace_string( string source, string search, string replace )</strong><br>
searches the source string for the search string and replaces all instances with the replace string</p>
<p><strong>string url_encode( string text )</strong><br>
<strong>string url_decode( string text )</strong><br>
Converts a string text into a formatted string for using with raw URLs or from a formatted string back into “normal” text.</p>
 
<p><strong>string [int] split_string( string source )</strong><br>
Returns a map of strings which is the passed string split into individual lines. Originally implemented for use when parsing session logs, but may see more uses in the future.
http://kolmafia.us/showthread.php?t=573 <br>
<strong>string [int] split_string( string source, string regex )</strong><br>
<strong>string [int,int] group_string( string source, string regex )</strong><br>
see this post located on the script repository for more information:  http://kolmafia.us/showthread.php?t=318 </p>
 
<strong>string [int] session_logs( string player, int day_count )</strong>
Gives access to the session logs saved by kolmafia. More details will be added when this function's own page is written. For now, more extensive details can be found here: http://kolmafia.us/showthread.php?t=573
 
<p><strong>buffer append( buffer source, string text )</strong><br>
Returns the source buffer with the string added on at the end.<br>
<strong>buffer append_tail( matcher regex, buffer source )</strong><br>
This function appends the text returned by a matcher to the end of the buffer text.

Revision as of 04:51, 3 March 2010

 void( print, string, [string] )

Prints the given string to the CLI and status line, optionally in the specified color.

string visit_url( string )

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

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

Returns the position of the second string in the first (or -1 if not found), optionally starting 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 at a specified position (defaults to remainder of string).

string 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, [rstring] )

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 )

This does... something regex-y. I dunno. [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 append_tail( matcher, buffer )

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