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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Comparison Operators in Javascript

  • 21-01-2006 6:02pm
    #1
    Registered Users, Registered Users 2 Posts: 7,987 ✭✭✭


    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,317 ✭✭✭✭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,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, Registered Users 2 Posts: 3,889 ✭✭✭cgarvey


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


Advertisement