Raised This Month: $ Target: $400
 0% 

empty string == ^0 ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-02-2006 , 17:17   empty string == ^0 ?
Reply With Quote #1

Code:
new myString[32] = ""; if(myString[0] == '^0')    // success

is this correct? as in, is the first character of an empty string the null character?
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 03-02-2006 , 17:23  
Reply With Quote #2

i don't know the answer to your question, however I know for what you probrably want to do you can also do
Code:
if(!strlen(myString))    // success

Hope that helps, I'm sure someone on these forums knows that [0] will read in an empty string though.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 03-02-2006 , 17:23  
Reply With Quote #3

should work
if not try this:
Code:
if( equal( string, "" ) )
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-02-2006 , 17:25  
Reply With Quote #4

thanks, chronic, just what i was looking for.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 03-02-2006 , 17:28  
Reply With Quote #5

Quote:
Originally Posted by GHW_Chronic
i don't know the answer to your question, however I know for what you probrably want to do you can also do
Code:
if(!strlen(myString))    // success

Hope that helps, I'm sure someone on these forums knows what [0] will read in an empty string though.
This was for my postcount.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-02-2006 , 17:30  
Reply With Quote #6

i'm not sure why you are quoting yourself. while it would still be handy to know the answer to my question, your method is a sure alternative that does exactly what i need, which is what i was thanking you for.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 03-02-2006 , 17:30  
Reply With Quote #7

Naah, don't do that, calling a native for this is unnecessary.

As you said, the first character of an empty string is a null character (because we use null-terminated strings), so you can (and should) do:

Code:
if(myString[0] == '^0') {    // Yup it's empty! }

same as:
Code:
if(myString[0] == 0) {    // Yup it's empty! }

Or simply:
Code:
if(!myString[0]) {    // Yup it's empty! }
__________________
hello, i am pm
PM is offline
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-02-2006 , 17:30  
Reply With Quote #8

thanks, PM!
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
SSJ2GOKU
Senior Member
Join Date: Oct 2005
Location: Belgium
Old 03-02-2006 , 18:39  
Reply With Quote #9

[offtopic]
hey chronic

what are those tiny letters
are ya making a contract with that guy?
SSJ2GOKU is offline
Send a message via MSN to SSJ2GOKU
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-02-2006 , 19:05  
Reply With Quote #10

Quote:
Originally Posted by GHW_Chronic
Quote:
Originally Posted by GHW_Chronic
i don't know the answer to your question, however I know for what you probrably want to do you can also do
Code:
if(!strlen(myString))    // success

Hope that helps, I'm sure someone on these forums knows what [0] will read in an empty string though.
This was for my postcount.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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 20:28.


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