Isnull
From SA-MP Wiki
(Difference between revisions)
Revision as of 08:00, 11 May 2015 MP2 (Talk | contribs) (Commonly used function, so could do with documentation. I know it's a simple macro, but still) ← Previous diff |
Revision as of 08:01, 11 May 2015 MP2 (Talk | contribs) (Lowercase title) Next diff → |
||
Line 1: | Line 1: | ||
+ | {{DisplayTitle|isnull}} | ||
+ | {{LowercaseFunction}} | ||
+ | |||
{{NotNative|function}} | {{NotNative|function}} | ||
Revision as of 08:01, 11 May 2015
isnull
Note: This function name starts with a lowercase letter. |
Description:
Checks whether a string is null (empty). More efficient than checking if strlen is 0.
(string)
string | The 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 | 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. |