AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Empty string (https://forums.alliedmods.net/showthread.php?t=188696)

Liverwiz 06-29-2012 13:19

Empty string
 
This seems like a silly question. But a question i've been having trouble figuring out...

How do i determine if a string is empty?

Code:

if(equali(string, "") ) // throws warnings
Code:

if(sizeof string < 2) // Throws 3 warnings
Code:

if(string[0]) // simply doesn't work
Code:

if(charsmax(string) < 2) // Throws errors & warnings
all of these are proceeded with
Code:

                formatex(string, charsmax(string), "[page]")

t3hNox 06-29-2012 13:23

Re: Empty string
 
You can use strlen(). Or maybe check if szString[0] = EOS.

<VeCo> 06-29-2012 13:24

Re: Empty string
 
PHP Code:

if(!string[0]) 

or
PHP Code:

if(string[0] == EOS

?

Liverwiz 06-29-2012 13:28

Re: Empty string
 
Quote:

Originally Posted by <VeCo> (Post 1739074)
[php]
PHP Code:

if(string[0] == EOS

?

What does EOS stand for? Just out of curiosity.....i'm testing that now.

micapat 06-29-2012 13:33

Re: Empty string
 
EOS = '^0' = 0

Liverwiz 06-29-2012 13:39

Re: Empty string
 
Quote:

Originally Posted by micapat (Post 1739079)
EOS = '^0' = 0

oh, thanks!

Code:

if(string[0] == EOS)
And it worked, guys! Thank you, very much.

mottzi 06-29-2012 14:09

Re: Empty string
 
Just for better understanding, EOS simply means end of string.

fysiks 06-30-2012 13:41

Re: Empty string
 
Quote:

Originally Posted by Liverwiz (Post 1739071)
Code:

if(string[0]) // simply doesn't work

This one works but it is actually checking if the string is not empty. To check if the string is empty you need to do if( !string[0] ).

Liverwiz 06-30-2012 14:02

Re: Empty string
 
Quote:

Originally Posted by fysiks (Post 1739818)
This one works but it is actually checking if the string is not empty. To check if the string is empty you need to do if( !string[0] ).

yeah....that explains why this works.
[php]if(pm_sound[0])
client_cmd(reciever, "speak ^"sound/%s^"", pm_sound)[/pm]

I figured that out after <VeCo>'s post and some fooling around.

fysiks 07-01-2012 14:28

Re: Empty string
 
Quote:

Originally Posted by Liverwiz (Post 1739843)
yeah....that explains why this works.
[php]if(pm_sound[0])
client_cmd(reciever, "speak ^"sound/%s^"", pm_sound)[/pm]

I figured that out after <VeCo>'s post and some fooling around.

Yeah, but I was just thinking that comparing to EOS is probably much better for readability.


All times are GMT -4. The time now is 15:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.