Replace string: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Heeheehee
m Formatting to eliminate template-breaking.
imported>Heeheehee
m Formatting and stuff. (Template-breaking is baaad.)
Line 35: Line 35:
description=Will place your Fullness and Spleen above the HP Image|
description=Will place your Fullness and Spleen above the HP Image|
code=<syntaxhighlight>
code=<syntaxhighlight>
void Icon_Charpane()
void main()
{
{
   buffer results;
   buffer results;
   results.append(visit_url());
   results.append(visit_url());
 
   string hp_gif = "<img src=\"/images/itemimages/hp.gif";
   if ( my_fullness() >= 1 )
  if ( my_fullness() >= 1 ) string full = "<tr>Fullness: <b>"+my_fullness()+"/"+fullness_limit()+"</b>";
  results.replace_string("<img src=\"/images/itemimages/hp.gif\"", "<tr><paragraph>Fullness:<b> "+my_fullness()
   if ( my_spleen_use() >= 1 ) string spleen = "<tr>Spleen: <b>"+my_spleen_use()+"/"+spleen_limit()+"</b>";
                          +"/"+fullness_limit()+"</b></tr><td align='center'><img src=\"/images/itemimages/hp.gif\"");
  results.insert(results.index_of(hp_gif), full + "<br />" + spleen + "<br />");
 
   if ( my_spleen_use() >= 1 )
  results.replace_string("<img src=\"/images/itemimages/hp.gif\"", "<tr>Spleen:<b> "+my_spleen_use()+"/"+spleen_limit()
                          +"</b></tr><td align='center'><img src=\"/images/itemimages/hp.gif\"");
   results.write();
   results.write();
}
void main()
{
Icon_Charpane();
}
}
</syntaxhighlight>}}|
</syntaxhighlight>}}|
needscode=yes|


special=Matches are made left-to-right, and once a portion of the supplied {{pspan|original}} is noted as a match, searching continues from the next character after said match.|
special=Matches are made left-to-right, and once a portion of the supplied {{pspan|original}} is noted as a match, searching continues from the next character after said match.|
}}
}}
{{RFI|Is the special note correct, or is the behavior different?|I'm having a hard time clarifying what I mean... see Discussion page}}
{{RFI|Is the special note correct, or is the behavior different?|I'm having a hard time clarifying what I mean... see Discussion page}}

Revision as of 01:38, 12 April 2010

Function Syntax

buffer replace_string(buffer original ,string find ,string replace )

buffer replace_string(string original ,string find ,string replace )

  • original is the starting string or buffer
  • find is the text to find in original
  • replace is the text to substitute for find

Searches through the supplied original text, replacing every instance of find with replace, and returns the result.

Code Sample

Will place your Fullness and Spleen above the HP Image

void main()
{
   buffer results;
   results.append(visit_url());
   string hp_gif = "<img src=\"/images/itemimages/hp.gif";
   if ( my_fullness() >= 1 ) string full = "<tr>Fullness: <b>"+my_fullness()+"/"+fullness_limit()+"</b>";
   if ( my_spleen_use() >= 1 ) string spleen = "<tr>Spleen: <b>"+my_spleen_use()+"/"+spleen_limit()+"</b>";
   results.insert(results.index_of(hp_gif), full + "<br />" + spleen + "<br />");
   results.write();
}

Special

Matches are made left-to-right, and once a portion of the supplied original is noted as a match, searching continues from the next character after said match.


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:

  • Is the special note correct, or is the behavior different?
  • I'm having a hard time clarifying what I mean... see Discussion page