Isnull

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search

MP2 (Talk | contribs)
(Commonly used function, so could do with documentation. I know it's a simple macro, but still)
Next diff →

Revision as of 08:00, 11 May 2015

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.