strlen and isnull
#1

isnull(string) is same as strlen(string) == 0 ?
Reply
#2

Isnull is used to check if a string is empty/null.

Strlen is used to get the length of a string.
Reply
#3

I don't use Isnull but strlen will return more then 0 even if someone fills it with space
Reply
#4

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).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)