-
-
Notifications
You must be signed in to change notification settings - Fork 18
is_string
CryoEagle edited this page Dec 26, 2018
·
7 revisions
Returns whether the given input is a string.
is_string(n)
Argument | Description |
---|---|
object n |
The variable to check |
Returns: bool
This function returns if the input variable is a string or not. If so, it returns true, if not, returns false.
string var = "Hello, World!";
if (is_string(var))
{
string message = "var is a string!";
}
The above code checks to see if var is a string, and because it is, sets the variable message to "var is a string!". This can be used to make sure a variable is a string before printing it, and if not, converting it into a string.
int str = 80;
if (is_string(str)) // str is now of type int so this won't be hit
{
draw_text(0,0,str);
}
else
{
string strConverted = sstring(str); // will cast (int)str to (string)strConverted
draw_text(0, 0, str); // we can then draw the string
}
The above code checks if str is a string, and if so, draws the text on the screen. If not, it will convert str to a string and then draw it.
Back to strings