AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   empty string == ^0 ? (https://forums.alliedmods.net/showthread.php?t=24800)

Kraugh 03-02-2006 17:17

empty string == ^0 ?
 
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?

GHW_Chronic 03-02-2006 17:23

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.

Greenberet 03-02-2006 17:23

should work
if not try this:
Code:
if( equal( string, "" ) )

Kraugh 03-02-2006 17:25

thanks, chronic, just what i was looking for.

GHW_Chronic 03-02-2006 17:28

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.

Kraugh 03-02-2006 17:30

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.

PM 03-02-2006 17:30

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! }

Kraugh 03-02-2006 17:30

thanks, PM!

SSJ2GOKU 03-02-2006 18:39

[offtopic]
hey chronic

what are those tiny letters :D
are ya making a contract with that guy? :lol:

Hawk552 03-02-2006 19:05

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.



All times are GMT -4. The time now is 20:28.

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