Results 1 to 5 of 5

Thread: Boolean String?

  1. #1
    Junior Member
    Join Date
    Mar 2003
    Posts
    26

    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?

  2. #2
    Ultimate Member DocEvi1's Avatar
    Join Date
    Dec 2001
    Posts
    2,330
    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
    Stefan

  3. #3
    Junior Member
    Join Date
    Mar 2003
    Posts
    26
    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?

  4. #4
    Junior Member
    Join Date
    Mar 2003
    Posts
    26
    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"

  5. #5
    Ultimate Member DocEvi1's Avatar
    Join Date
    Dec 2001
    Posts
    2,330
    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
    Stefan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •