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

  • 21-01-2006 07:02PM
    #1
    Registered Users, Registered Users 2 Posts: 8,411 ✭✭✭


    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, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    != would be the same as <>


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


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


  • Registered Users, Registered Users 2 Posts: 5,333 ✭✭✭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, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


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


Advertisement