-
-
Notifications
You must be signed in to change notification settings - Fork 18
is_string
Matěj Štágl edited this page Dec 1, 2018
·
7 revisions
Returns whether the given input is a string.
is_string(n);
Argument | Description |
---|---|
object t |
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.
var1 = "Hello, World!"
if (is_string(var1))
{
string message = "var1 is a string!"
}
The above code checks to see if var1 is a string, and if it is, sets the variable message to "var1 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