Skip to content

is_string

Matěj Štágl edited this page Dec 1, 2018 · 7 revisions

is_string

Returns whether the given input is a string.

Syntax:

is_string(n);
Argument Description
object t The variable to check.

Returns: bool

Description

This function returns if the input variable is a string or not. If so, it returns true, if not, returns false.

Example:

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.

Example 2:

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

Clone this wiki locally