Raised This Month: $ Target: $400
 0% 

Empty string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-29-2012 , 13:19   Empty string
Reply With Quote #1

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]")
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-29-2012 at 13:19.
Liverwiz is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 06-29-2012 , 13:23   Re: Empty string
Reply With Quote #2

You can use strlen(). Or maybe check if szString[0] = EOS.
t3hNox is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-29-2012 , 13:24   Re: Empty string
Reply With Quote #3

PHP Code:
if(!string[0]) 
or
PHP Code:
if(string[0] == EOS
?
__________________
<VeCo> is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-29-2012 , 13:28   Re: Empty string
Reply With Quote #4

Quote:
Originally Posted by <VeCo> View Post
[php]
PHP Code:
if(string[0] == EOS
?
What does EOS stand for? Just out of curiosity.....i'm testing that now.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 06-29-2012 , 13:33   Re: Empty string
Reply With Quote #5

EOS = '^0' = 0
__________________
micapat is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-29-2012 , 13:39   Re: Empty string
Reply With Quote #6

Quote:
Originally Posted by micapat View Post
EOS = '^0' = 0
oh, thanks!

Code:
if(string[0] == EOS)
And it worked, guys! Thank you, very much.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 06-29-2012 , 14:09   Re: Empty string
Reply With Quote #7

Just for better understanding, EOS simply means end of string.
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-30-2012 , 13:41   Re: Empty string
Reply With Quote #8

Quote:
Originally Posted by Liverwiz View Post
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] ).
__________________

Last edited by fysiks; 06-30-2012 at 13:41.
fysiks is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-30-2012 , 14:02   Re: Empty string
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-01-2012 , 14:28   Re: Empty string
Reply With Quote #10

Quote:
Originally Posted by Liverwiz View Post
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.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:25.


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