strlen and isnull - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: strlen and isnull (
/showthread.php?tid=635642)
strlen and isnull -
Bussyman - 11.06.2017
isnull(string) is same as strlen(string) == 0 ?
Re: strlen and isnull -
StrikerZ - 11.06.2017
Isnull is used to check if a string is empty/null.
Strlen is used to get the length of a string.
Re: strlen and isnull -
coool - 11.06.2017
I don't use Isnull but strlen will return more then 0 even if someone fills it with space
Re: strlen and isnull -
yugecin - 20.02.2019
Quote:
Originally Posted by ******
No:
1) Checking if a string is empty by using "strlen" is terrible, because if the string isn't empty it will take much longer.
2) Not all "null" strings are actually length zero. There is a bug in the PAWN VM which means you can't pass fully empty strings (actually, I don't think there is, but I thought there was when I wrote "CallRemoteFunction"). So instead of just "\0", it passes "\1\0" for empty strings. So if you use ZCMD and type a command with no parameters, "params" will have length 1, but "isnull" knows about this and will return true.
|
Interesting, was just about to open a topic about the origins of
isnull when I found this.
So basically when one does
CallRemoteFunction("myfunc", "s", ""), the native code will invoke
myfunc but with a modified argument being
"\1" instead (and the same for
CallLocalFunction I assume), but except for these cases there's no real reason to use the common
isnull everywhere instead of a
0 check on the first position, correct?
Fascinating how almost nobody seems to question things like this (or not publicly) and just 'do what everyone else does' (including the wiki, although that's perhaps because explaining this whole thing would be too confusing for the average scripter).