<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Alacrity</id>
	<title>Kolmafia - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Alacrity"/>
	<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Special:Contributions/Alacrity"/>
	<updated>2026-04-25T03:18:10Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=String_Handling_Routines&amp;diff=1318</id>
		<title>String Handling Routines</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=String_Handling_Routines&amp;diff=1318"/>
		<updated>2007-08-19T23:26:13Z</updated>

		<summary type="html">&lt;p&gt;Alacrity: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p&amp;gt;&amp;lt;em&amp;gt;Under Construction&amp;lt;/em&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;void print( string helloworld )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;void echo( string helloworld )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Prints the given string to the graphical CLI window and to the status line of the main Adventuring window.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string visit_url( string url )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
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.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string location_to_url( location place )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns the URL that would need to be accessed to visit the specified location.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;boolean contains_text( string source, string query )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Reveals if the query string is a substring of the source string.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;int extract_meat( string text )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
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.*&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;int [item] extract_items( string text )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
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.*&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;int length( string text )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Returns the length of the given string.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;int index_of( string source, string search )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Returns the first index of a given substring in a string.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;int index_of( string source, string search, int start )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Returns the next index of a given substring in a string starting from the given position.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;int last_index_of( string source, string search )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Returns the last index of a given substring in a string.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string substring( string source, int startfrom )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Returns the substring of the given string starting from the given character position in the string, and ending at the last character.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;string substring( string source, int start, int end )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string replace_string( string source, string search, string replace )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
searches the source string for the search string and replaces all instances with the replace string&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string url_encode( string text )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;string url_decode( string text )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Converts a string text into a formatted string for using with raw URLs or from a formatted string back into “normal” text.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string [int] split_string( string source )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
http://kolmafia.us/index.php/topic,794.msg3868.html#msg3868 &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;string [int] split_string( string source, string regex )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;string [int,int] group_string( string source, string regex )&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
see this post located on the script repository for more information:  http://kolmafia.us/index.php/topic,451.msg2235.html#msg2235 &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;string [int] session_logs( string player, int day_count )&amp;lt;/strong&amp;gt;&lt;br /&gt;
Gives access to the session logs saved by kolmafia. More details will be added when this function&#039;s own page is written. For now, more extensive details can be found here: http://kolmafia.us/index.php/topic,794.msg3879.html#msg3879&lt;/div&gt;</summary>
		<author><name>Alacrity</name></author>
	</entry>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Talk:String_Handling_Routines&amp;diff=2050</id>
		<title>Talk:String Handling Routines</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Talk:String_Handling_Routines&amp;diff=2050"/>
		<updated>2007-08-19T23:14:32Z</updated>

		<summary type="html">&lt;p&gt;Alacrity: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;So wtf does group_string actually do?  The linked &amp;quot;descriptive&amp;quot; post has an utterly unhelpful example.  Has anyone ever used it for anything?&lt;br /&gt;
&lt;br /&gt;
Groups a string into a map using a regular expression. To understand the function you must know.&lt;br /&gt;
1. What maps are and how they are used.&lt;br /&gt;
2. Understand what regular expressions are and how to create them.&lt;br /&gt;
&lt;br /&gt;
Using the original post:&lt;br /&gt;
&lt;br /&gt;
FUNCTION DEFINTION: string [int,int] group_string( string source, string regex )&lt;br /&gt;
EXAMPLE: string [int,int] test = group_string( &amp;quot;This is a test&amp;quot;, &amp;quot;([a-z]+) &amp;quot; );&lt;br /&gt;
&lt;br /&gt;
Example Breakdown:&lt;br /&gt;
&#039;&#039;&#039;string [int,int]&#039;&#039;&#039; Define a map. Two dimensional. The indices are integers. The data is stored as a string.&lt;br /&gt;
&#039;&#039;&#039;test&#039;&#039;&#039; Define the map with name &#039;&#039;&#039;test&#039;&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;group_string&#039;&#039;&#039; Call the function.&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;This is a Test&amp;quot;&#039;&#039;&#039; Feeding the function a sample string.&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;([a-z]+) &amp;quot;&#039;&#039;&#039; Your regular expression.&lt;br /&gt;
&lt;br /&gt;
Regular expressions deal with pattern matching. You want the function to find a particular pattern. The function then returns that pattern, or the stuff before it, or the stuff after it, or splits them appart, or squeezes them together. So what does this regular expression look for? &lt;br /&gt;
&#039;&#039;&#039;The Parenthesis ():&#039;&#039;&#039; Tell the function this is a group of characters.&lt;br /&gt;
&#039;&#039;&#039;[a-z]:&#039;&#039;&#039; Tell us they will be lower case letters.&lt;br /&gt;
&#039;&#039;&#039;+:&#039;&#039;&#039; Tell us to look for one or more characters.&lt;br /&gt;
That space between the ) and &amp;quot; Tells us the pattern ends in a space.&lt;br /&gt;
&lt;br /&gt;
Thus reading down the string.&lt;br /&gt;
T = Does not match [a-z] is a capital letter.&lt;br /&gt;
h = Matches [a-z]. Starting Group&lt;br /&gt;
i = Matches [a-z]&lt;br /&gt;
s = Matches [a-z]&lt;br /&gt;
  = Matches space. First group found and is &amp;quot;his &amp;quot;&lt;br /&gt;
i = Matches [a-z]. Starting Group&lt;br /&gt;
s = Matches [a-z]&lt;br /&gt;
  = Matches space. Second group found, and is &amp;quot;is &amp;quot;&lt;br /&gt;
a = Matches [a-z]. Starting Group&lt;br /&gt;
  = Matches space. Third group found, and is &amp;quot;a &amp;quot;&lt;br /&gt;
t = Matches [a-z]. Starting Group&lt;br /&gt;
e = Matches [a-z]&lt;br /&gt;
s = Matches [a-z]&lt;br /&gt;
t = Matches [a-z]&lt;br /&gt;
End of line. No more matches. Stop.&lt;br /&gt;
&lt;br /&gt;
Thus, trusting the post, the map would be:&lt;br /&gt;
&lt;br /&gt;
test[0][0] =&amp;gt; &amp;quot;his &amp;quot;&lt;br /&gt;
test[0][1] =&amp;gt; &amp;quot;his&amp;quot;&lt;br /&gt;
test[1][0] =&amp;gt; &amp;quot;is &amp;quot;&lt;br /&gt;
test[1][1] =&amp;gt; &amp;quot;is&amp;quot;&lt;br /&gt;
test[2][0] =&amp;gt; &amp;quot;a &amp;quot;&lt;br /&gt;
test[2][1] =&amp;gt; &amp;quot;a&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I personally haven&#039;t used it. Would be used in parsing a page by hand.&lt;/div&gt;</summary>
		<author><name>Alacrity</name></author>
	</entry>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Miscellaneous_Functions&amp;diff=933</id>
		<title>Miscellaneous Functions</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Miscellaneous_Functions&amp;diff=933"/>
		<updated>2007-08-19T23:12:34Z</updated>

		<summary type="html">&lt;p&gt;Alacrity: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Part 6 - Miscellaneous ==&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;em&amp;gt;Mostly internal stuff. Some good for everyone, some only for ASH wizards.&amp;lt;/em&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;void print( string helloworld )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Prints the given string to the graphical CLI window and to the status line of the main Adventuring window&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;boolean cli_execute( string command )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Executes the given command as if it were entered into the graphical CLI window. This can be used for CLI commands or, if you&amp;amp;#8217;re careful and not an asshat, for raw URLs.&amp;lt;br /&amp;gt;&lt;br /&gt;
See the [http://kolmafia.sourceforge.net/scripting.html CLI manual] for more details.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;em&amp;gt;Sample&amp;lt;/em&amp;gt;:[[%28ASHRM%29_Code_Samples#Sample_4:_Hedging|Hedging]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;void wait( int delay )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Does nothing for the desired number of seconds.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string get_property( string key )&amp;lt;br /&amp;gt;&lt;br /&gt;
boolean set_property( string key, string value )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Gets or sets a stored property from your character&amp;amp;#8217;s .kcs file.&amp;lt;br /&amp;gt;&lt;br /&gt;
The KoLmafia [[%28ASHRM%29_KoLMafia_Properties|properties]] page contains details on many of the keys that are available for access.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;em&amp;gt;Sample&amp;lt;/em&amp;gt;:[[%28ASHRM%29_Code_Samples#Sample_2:_Battlefield_gather|Battlefield_gather]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;boolean file_to_map( string file_to_load, map map_to_fill )&amp;lt;br /&amp;gt;&lt;br /&gt;
boolean map_to_file( map map_to_save, string file_to_write )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Loads and saves maps as tab-delimited text files.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;int random( int range )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Generates a random integer between 0 and (range-1) inclusive.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;int round( float ratio )&amp;lt;br /&amp;gt;&lt;br /&gt;
int floor( float ratio )&amp;lt;br /&amp;gt;&lt;br /&gt;
int ceil( float ratio )&amp;lt;br /&amp;gt;&lt;br /&gt;
int truncate( float ratio )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Returns an integer near the given real number.  Respectively, it returns the nearest, next lowest, next highest, and decimal-stripped integer.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;int count( map )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Returns the number of defined keys for the aggregate.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;void clear( map )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Remove all keys from a map. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;void disable( string function_name )&amp;lt;br /&amp;gt;&lt;br /&gt;
void enable( string function_name )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
For debugging purposes disables or enables the indicated function&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;float square_root( float value )&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
returns the square root of the passed value&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;string today_to_string()&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Returns today&amp;amp;#8217;s (real-world) date in the form yyyymmdd.  It is based on your computer&amp;amp;#8217;s system date&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Alacrity</name></author>
	</entry>
</feed>