Skip to content

is_string

CryoEagle edited this page Dec 26, 2018 · 7 revisions

is_string

Returns whether the given input is a string.

Syntax:

is_string(n)
Argument Description
object n 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:

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.

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