-
Boolean String?
I'm sure I've just missed something in my textbook relating to this exact topic, and this is going to sound like a stupid question to people in the know but:
Can you ask a boolean question of a String? I want to say if nameString is not equal to "null" then do something. If not, is a another way I can get the same result?
-
Ultimate Member
depends on the language is the short answer, yes is the long one
for instance in java:
Code:
String s = "hello";
String t = "hi";
if (s.equals(t) )
{
//does nothing
}
else
{
//say hello
}
i.e. the function ".equals" returns a boolean expression.
The answer is yes btw
-
thanks for that, if forgot to mention java was the language. what can i add to that to make 's' not equal 't'? for example '!=' as opposed to '=='. and are there any java code dictionaries out there i can download so i can work these things out myself?
-
nevermind, problem solved. i was relying on the default value of empty strings (ie null) behaving like a string, this is not the case so i just gave all unused strings the value "empty"
-
Ultimate Member
the if statement would be
Code:
if( ! s.equals(t) )
you could assign the empty string to be "".
The API spec is : http://java.sun.com/reference/api/index.html but you can download it from http://java.sun.com/docs/index.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|