Isnull

From SA-MP Wiki

Jump to: navigation, search

isnull

Image:Farm-Fresh text lowercase.png Note: This function name starts with a lowercase letter.


Image:32px-Ambox_warning_orange.png

Note

This is not a native function. It must first be defined in scripts to be used.


Description:

Checks whether a string is null (empty). More efficient than checking if strlen is 0.


Parameters:
(string)
stringThe string to check for emptiness


Definition:

#if !defined isnull
    #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

Example Usage:

if(isnull(string))
{
    // Do something
}
Tip

Image:Light_bulb_icon.png

isnull is more efficient than strlen() because isnull simply checks if the first character of a string is the null-terminator (end of string), while strlen goes through every character of the string.

They are almost identical if the string IS empty, but if it is not then strlen has to go through every single character (which could be thousands) until it reaches the end.

Personal tools
Navigation
Toolbox