Difference between revisions of "String Handling Routines"

From Kolmafia
Jump to navigation Jump to search
 
(239 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[http://motorolafaxmodem.longroot.info/ motorola fax modem] [http://nokia3230.longroot.info/ nokia 3230] [http://dights.info/web/clothingbargains.html clothing bargains] [http://m-and-an.info/plymouthroadrunner/ plymouth roadrunner] [http://dights.info/web/carafate.html carafate] [http://radiosaid.info/blog/tracfoneprogramming.html tracfone programming codes] [http://couplefucking.runfish.info/ couple fucking] [http://dights.info/web/cdoryboats.html c dory boats] [http://propoxyphene-n.threader.info/ propoxyphene-n] [http://onlinefabric.alexinic.info/ online fabric] [http://gamesfreepc.runfish.info/ games free pc downloads] [http://ringbacktones.runfish.info/ ringback tones] [http://m-and-an.info/ m-and-an.info] [http://radiosaid.info/blog/bestcellphoneprepaid.html best cell phone prepaid service] [http://radiosaid.info/blog/adults.html adults] [http://floridalotto.tiptilt.info/ florida lotto] [http://pharmacytechnician.longroot.info/ pharmacy technician jobs] [http://asianmen.runfish.info/ asian men] [http://tranxene.longroot.info/ tranxene] [http://pornonocreditcard.alexinic.info/ porno no credit card] [http://konicaminolta.threader.info/ konica minolta] [http://urbanrebound.longroot.info/ urban rebound] [http://m-and-an.info/unlistedphone/ unlisted phone number] [http://hydrocortisone.dirges.info/ hydrocortisone] [http://wreath.runfish.info/ wreath] [http://lowthyroidsymptom.threader.info/ low thyroid symptom] [http://asssex.dirges.info/ ass sex] [http://gastricband.dirges.info/ gastric band] [http://weldingprocedures.alexinic.info/ welding procedures] [http://pradareplicahandbag.dirges.info/ prada replica handbag] [http://vuarnet.tiptilt.info/ vuarnet] [http://loseweightwhile.longroot.info/ lose weight while you sleep] [http://vore.threader.info/ vore] [http://dights.info/web/avgantivirus.html avg antivirus free edition] [http://bratzgame.alexinic.info/ bratz game] [http://dights.info/web/lungcancerdrugs.html lung cancer drugs] [http://radiosaid.info/blog/accreditedonline.html accredited online electronics engineering degree] [http://radiosaid.info/blog/bettingexchange.html betting exchange] [http://penileenhancement.longroot.info/ penile enhancement] [http://phytyl.info/topic/moneytransfers.html money transfers] [http://m-and-an.info/johnnycash/ johnny cash] [http://deck.longroot.info/ deck] [http://radiosaid.info/blog/truckbedcover.html truck bed cover] [http://cumnorthpeter.runfish.info/ cum north peter shot] [http://phytyl.info/topic/iliketomoveitmp3.html i like to move it mp3] [http://m-and-an.info/currentmortgage/ current mortgage rate] [http://torrent.longroot.info/ torrent] [http://analsextoys.threader.info/ anal sex toys] [http://radiosaid.info/blog/varsitycheerleading.html varsity cheerleading uniform] [http://amsterdamcheap.runfish.info/ amsterdam cheap hotel] [http://enemastories.tiptilt.info/ enema stories] [http://timesheet.runfish.info/ timesheet] [http://m-and-an.info/tampatushyfest/ tampa tushy fest] [http://dights.info/web/sanandreas.html san andreas] [http://shootingstartatoos.runfish.info/ shooting star tatoos] [http://phytyl.info/ phytyl.info] [http://hondaridgeline.dirges.info/ honda ridgeline] [http://dights.info/web/ibuprofen800mg.html ibuprofen 800mg] [http://cheapperfume.tiptilt.info/ cheap perfume] [http://weddinggiftbasket.longroot.info/ wedding gift basket] [http://photosrussian.dirges.info/ photos russian women] [http://m-and-an.info/hardware/ hardware] [http://phytyl.info/topic/homedepotprintable.html home depot printable coupons] [http://radiosaid.info/blog/coffeeandcaffeine.html coffee and caffeine] [http://customcarpartand.tiptilt.info/ custom car part and accessory] [http://nudeart.runfish.info/ nude art] [http://corduroyskirt.dirges.info/ corduroy skirt] [http://southafricaphone.longroot.info/ south africa phone directory] [http://philipsremotecodes.tiptilt.info/ philips remote codes] [http://phytyl.info/topic/westsidemusic.html west side music codes] [http://dights.info/web/hersheyschocolate.html hersheys chocolate] [http://ultimatesurrender.threader.info/ ultimate surrender] [http://tiptilt.info/index4_250.html map] [http://collectableantiques.threader.info/ collectable antiques] [http://wholesaleperfume.dirges.info/ wholesale perfume] [http://freeadawarespyware.longroot.info/ free adaware spyware] [http://dights.info/web/wirelessprinter.html wireless printer] [http://m-and-an.info/skimpybikini/ skimpy bikini] [http://americangolf.alexinic.info/ american golf] [http://dights.info/web/youngsexpics.html young sex pics] [http://ocn.dirges.info/ ocn] [http://demfranchizeboyz.dirges.info/ dem franchize boyz ridin rims] [http://phytyl.info/topic/us3000airlines.html us3000 airlines] [http://weddingsongfor.longroot.info/ wedding song for reception] [http://m-and-an.info/nataliegulbis/ natalie gulbis] [http://dights.info/web/vacationcruises.html vacation cruises] [http://dights.info/web/obesitystatistics.html obesity statistics] [http://formalpromhairstyles.tiptilt.info/ formal prom hair styles] [http://isagenixreview.runfish.info/ isagenix review] [http://heeljob.dirges.info/ heeljob] [http://radiosaid.info/blog/amityvillehorror.html amityville horror house] [http://pregnantporn.longroot.info/ pregnant porn] [http://namemeaning.runfish.info/ name meaning] [http://m-and-an.info/businesssoftware/ business software] [http://dights.info/web/singleparents.html single parents] [http://bankofamerica.tiptilt.info/ bankofamerica] [http://homedepotstore.dirges.info/ home depot store] [http://smock.runfish.info/ smock] [http://stressrelief.tiptilt.info/ stress relief] [http://alexinic.info/index3_250.html site]  
+
{{TOCright}}
== Part  8 - String Handling Routines ==
+
==Simple==
<p><em>Under Construction</em></p>
+
{{Flink|string|to_lower_case|string|desc=Converts all upper-case alphabetic characters to lower-case.}}
<p><strong>void print( string helloworld )</strong><br>
+
{{Flink|string|to_upper_case|string|desc=Converts all lower-case alphabetic characters to upper-case.}}
<strong>void echo( string helloworld )</strong><br>
+
{{Flink|string|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|int|extract_meat|string|desc=Returns the number of meat embedded in a string.}}
<p><strong>string visit_url( string url )</strong><br>
+
{{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.}}
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|length|string|desc=Returns the number of characters in the specified string.}}
<p><strong>string location_to_url( location place )</strong><br>
+
{{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}}
  
Returns the URL that would need to be accessed to visit the specified location.</p>
+
==Regular Expressions==
<p><strong>boolean contains_text( string source, string query )</strong><br>
+
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.
Reveals if the query string is a substring of the source string.</p>
 
<p><strong>int extract_meat( string text )</strong><br>
 
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>
 
<p><strong>int [item] extract_items( string text )</strong><br>
 
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>
 
<p><strong>int length( string text )</strong><br>
 
Returns the length of the given string.</p>
 
  
<p><strong>int index_of( string source, string search )</strong><br>
+
{{Flink|matcher|create_matcher|string|string|desc=Creates a matcher from a pattern and input string.}}
Returns the first index of a given substring in a string.<br>
+
{{Flink|matcher|reset|matcher|{{opt|string}}|desc=Resets matcher to search from beginning of string, possibly with new input.}}
<strong>int index_of( string source, string search, int start )</strong><br>
+
{{Flink|int|group_count|matcher|desc=Returns the number of capturing groups in the pattern.}}
Returns the next index of a given substring in a string starting from the given position.<br>
+
{{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]}}
<strong>int last_index_of( string source, string search )</strong><br>
+
{{Flink|int|start|matcher|{{opt|int}}|desc=Returns the starting index of the previous or specified capturing group.}}
Returns the last index of a given substring in a string.</p>
+
{{Flink|int|end|matcher|{{opt|int}}|desc=Returns the ending index of the previous or specified capturing group plus 1.}}
<p><strong>string substring( string source, int startfrom )</strong><br>
+
{{Flink|boolean|find|matcher|desc=Finds the next instance of the pattern or returns false if no more matches exist.}}
Returns the substring of the given string starting from the given character position in the string, and ending at the last character.<br>
+
{{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.}}
<strong>string substring( string source, int start, int end )</strong><br>
+
{{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.}}
  
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>
+
[[Category:Scripting]]
<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/index.php/topic,794.msg3868.html#msg3868 <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/index.php/topic,451.msg2235.html#msg2235 </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/index.php/topic,794.msg3879.html#msg3879
 

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.