Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Comparison Operators in Javascript

Options
  • 21-01-2006 7:02pm
    #1
    Registered Users Posts: 7,396 ✭✭✭


    Hi,

    Can you have a like command in javascript i.e.

    If (x like '%HelloWorld%)
    {
    then do this
    }
    else
    {
    do this
    }

    I can't find it anywhere

    All i can find is == , != , === and the <> but not like.

    Please help


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    != would be the same as <>


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Google for regular expressions. Javascript implements regular expressions for pattern matching. The Like operator is an SQL operator.


  • Registered Users Posts: 5,335 ✭✭✭Cake Fiend


    Or you could lever whatever is java's standard does_string_contain_this_string( string1 , string2 ) function to do it - strstr() or whatever for a quick and dirty fix.


  • Registered Users Posts: 3,884 ✭✭✭cgarvey


    Something like the following should work:
    if( x && x.substring( 'HelloWorld' ) > -1 ) {
      // then do this
    }
    else {
      // do this
    }
    


Advertisement