Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to check a string for equality to more then one thing..

    I want to make it so that the string is being checked if its equal to something OR something else...

    something like this :

    Code:
    if (diag.equalsIgnoreCase("Y" || "YES"))
    obviously the || doesn't work ...help please?

  • #2
    Regular Coder cs_student's Avatar
    Join Date
    Oct 2009
    Location
    ~/
    Posts
    195
    Thanks
    2
    Thanked 22 Times in 22 Posts
    If you want to do it in just one method call you are going to have to use Regular Expressions.

    However, if you just want to check if the string is equal to "Y" or "YES" you could use the logical or in-between method calls.


    ie
    Code:
    if( str.equalsIgnoreCase("y") || str.equalsIgnoreCase("yes") )
        // condition is true if the string is y or yes regardless of case
    When you tried the approach you gave it checked if the string diag was equal to the string "Y" || "YES" regardless of case.

    Regards,

    cs_student

  • Users who have thanked cs_student for this post:

    NoobCoder8769 (01-09-2010)

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks, I used the code you gave me .


  •  

    Posting Permissions

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