Raised This Month: $51 Target: $400
 12% 

How check whether the string is empty?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zer0_CooL
Junior Member
Join Date: Jul 2012
Old 07-30-2012 , 13:52   How check whether the string is empty?
Reply With Quote #1

Hello guys!
How check whether the string is empty?
PHP Code:
new StringText[512]

...........
...........
...........

if (
StringText[0]=='^n')
return 
true // string is empty
else return false // string is not empty 
This is correct?

Last edited by Zer0_CooL; 07-30-2012 at 13:54.
Zer0_CooL is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 07-30-2012 , 14:00   Re: How check whether the string is empty?
Reply With Quote #2

Check it against EOS:
Code:
if ( szText[0] == EOS )
Note that EOS is equal to '^0' and 0 in pawn.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 07-30-2012 , 14:01   Re: How check whether the string is empty?
Reply With Quote #3

if (!StringText[0])
jimaway is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-30-2012 , 14:01   Re: How check whether the string is empty?
Reply With Quote #4

Replace ''^n" by EOS.

You don't have to explicit it if you want.

if( StringText[0] ) // not empty
if( !StringText[0] ) // empty
__________________
Arkshine is offline
darktemplar
Member
Join Date: Sep 2009
Old 07-31-2012 , 09:09   Re: How check whether the string is empty?
Reply With Quote #5

in my opinion, i think he should use this condition :

if (equal(szString, ""))
return 1 // The string is empty
darktemplar is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-31-2012 , 09:47   Re: How check whether the string is empty?
Reply With Quote #6

Quote:
Originally Posted by darktemplar View Post
in my opinion, i think he should use this condition :

if (equal(szString, ""))
return 1 // The string is empty
No he shouldn't, it's an unnecessary native call.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-31-2012 , 20:31   Re: How check whether the string is empty?
Reply With Quote #7

Quote:
Originally Posted by darktemplar View Post
in my opinion, i think he should use this condition :

if (equal(szString, ""))
return 1 // The string is empty
A null-terminated string ends where the first null character ('^n', 0, or EOS) is located. If the very first character in a string is EOS, then guess what, it's empty. Use what Emp posted, no sense in wasting a native call on something like this..
__________________
Bugsy 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 09:26.


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