Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Comparison Operators in Javascript

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


    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