Difference between revisions of "Contains text"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
m
imported>Bumcheekcity
m
Line 43: Line 43:
 
   }
 
   }
 
   return false;
 
   return false;
 +
}
 +
</syntaxhighlight>
 +
}}
 +
{{CodeSample|
 +
description=Or this, more concise version...|
 +
code=
 +
<syntaxhighlight>
 +
boolean in_clan(){
 +
      return contains_text(visit_url("showplayer.php?who=" + my_id().to_string()), "showclan.php?whichclan");
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 09:06, 16 October 2010

Function Syntax

boolean contains_text(string str ,string substring )

  • str is the string you want to test.
  • substring is the substring you want to check is present inside str.

Returns true if substring can be found within str.

Code Samples

This function tests to see whether the string "Hello World!" contains the word "World".

boolean string_check(){
   if(contains_text("Hello World!" , "World")){
      return true;
   }
   return false;
}

This function tests to see whether a character is in a clan.

boolean in_clan(){
   string character = visit_url("showplayer.php?who=" + my_id().to_string());
   if(contains_text(character , "showclan.php?whichclan")){
      return true;
   }
   return false;
}

Or this, more concise version...

boolean in_clan(){
      return contains_text(visit_url("showplayer.php?who=" + my_id().to_string()), "showclan.php?whichclan");
}

See Also

visit_url() | my_id() | to_string()