Replace

From Kolmafia
Revision as of 06:53, 6 May 2010 by imported>Bale (Created page with '{{ #vardefine:name|replace}}{{ #vardefine:return_type|buffer}}{{ FunctionPage| name={{#var:name}}| function_category=XXXXXXXXXX| function1={{Function| name={{#var:name}}| aggre…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Function Syntax

buffer replace(buffer original ,int index1 ,int index2 ,string new  is the new string to insert into that position)

  • original is the starting string or buffer
  • index1 is the index of the first character to replace
  • index2 is the index of the second character to replace
  • new

Replaces every character in the original text between int index1  and int index2  with the string new  string and returns the result.

Code Sample

Replaces the center image of the Cyrpt (it's blank, don't worry) with some information regarding the noncombats of the zones.

void main() {
   buffer original;
   append(original, visit_url());
 
   string old = "<img src=\"http://images.kingdomofloathing.com/otherimages/cyrpt/cyrpt5.gif\">";
   string cyrpt = "<font size=1>&lt;- Muscle &nbsp; &nbsp; Mys -&gt;<br />"
   + "&lt;- Mox &nbsp; &nbsp; All -&gt;</font>";
   
   int index1 = index_of(original, old);
   
   replace(original, index1, length(old)+ index1, cyrpt);
 
   write(original);
}

See Also

replace_string() | index_of() | last_index_of()