Contains text: Difference between revisions
Jump to navigation
Jump to search
imported>Grotfang mNo edit summary |
Convert to Template:Function2 format |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{ | <onlyinclude>{{{{{format|Function2}}} | ||
|name=contains_text | |||
|function1.return_type=boolean | |||
|function1.description=Returns true if the first string contains the second string. | |||
|function1.param1=str | |||
|function1.param1.type=string | |||
name= | |function1.param1.description=String to search in | ||
|function1.param2=substring | |||
|function1.param2.type=string | |||
function1= | |function1.param2.description=Substring to check for | ||
|description= | |||
|code1={{CodeSample | |||
|title=Code Samples | |||
|description=This function checks whether the string "Hello World!" contains the word "World". | |||
|code= | |||
<syntaxhighlight lang="d"> | |||
boolean string_check() | |||
{ | |||
if ( contains_text("Hello World!" , "World" ) ) | |||
{ | |||
code1={{CodeSample| | |||
title=Code Samples| | |||
description=This function | |||
code= | |||
<syntaxhighlight> | |||
boolean string_check(){ | |||
if(contains_text("Hello World!" , "World")){ | |||
return true; | return true; | ||
} | } | ||
Line 33: | Line 24: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}}| | }} | ||
|code2={{CodeSample | |||
code2={{CodeSample| | |description=This function checks whether a character is in a clan. | ||
description=This function | |code= | ||
code= | <syntaxhighlight lang="d"> | ||
<syntaxhighlight> | boolean in_clan() | ||
boolean in_clan(){ | { | ||
string character = visit_url("showplayer.php?who=" + my_id().to_string()); | string character = visit_url( "showplayer.php?who=" + my_id().to_string() ); | ||
if(contains_text(character , "showclan.php?whichclan")){ | if ( contains_text( character , "showclan.php?whichclan" ) ) | ||
{ | |||
return true; | return true; | ||
} | } | ||
Line 47: | Line 39: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}}| | }} | ||
|code3={{CodeSample| | |||
|description=Or this, more concise version... | |||
|code= | |||
<syntaxhighlight lang="d"> | |||
boolean in_clan() | |||
{ | |||
return contains_text( visit_url( "showplayer.php?who=" + my_id().to_string() ), "showclan.php?whichclan" ); | |||
} | |||
</syntaxhighlight> | |||
}} | }} | ||
|see_also={{SeeAlso/Substring Search}} | |||
}}</onlyinclude> | |||
[[Category:String Handling Routines]] |
Latest revision as of 12:42, 23 December 2020
Function Syntax
boolean contains_text( string str, string substring )
- Returns true if the first string contains the second string.
- str: String to search in
- substring: Substring to check for
Code Samples
This function checks whether the string "Hello World!" contains the word "World".
boolean string_check()
{
if ( contains_text("Hello World!" , "World" ) )
{
return true;
}
return false;
}
This function checks 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" );
}