Author Topic: How to check if a string variable has nothing?  (Read 698 times)

I've tried, I didn't get it to work.


Why would it have nothing as in the variable hasn't been assigned to anything or nothing as in the variable = 0?

I'm not sure I understood what you just said.

If it's a string, you have to use $= ""
if you just use == 0 it will always be true because trying to convert a string to a number will always be 0

I'm not sure I understood what you just said.

If it's a string, you have to use $= ""
if you just use == 0 it will always be true because trying to convert a string to a number will always be 0

If the string begins with something numeric (e.g. 1234cow) it'd be converted to an integer of 1234 for an integer comparison.

Interesting, didn't know that.

So, is "$=" for string comparison and "==" for number comparison? What would be the one if a string isn't equal to another. Something like this perhaps?
Code: [Select]
if(%theString $! "")
{
<code>
}


I'm not sure I understood what you just said.

If it's a string, you have to use $= ""
if you just use == 0 it will always be true because trying to convert a string to a number will always be 0
!$=
Thanks

I use:
if (%str $= "")

or

if (strlen(%str) == 0)

both work to check if a string contains nothing.

As good a reference as any.

Specifically the first part, thought the whole thing is useful.

As good a reference as any.

Specifically the first part, thought the whole thing is useful.
This looks tasty..... :D