• Seaching Strings

    From Cyclops@VERT/SRBBS to All on Tuesday, April 04, 2006 14:51:00
    How does one do a simple string search in js?

    I want to get a simple true/false answer with if string1 is inside string2 at any position in the string.

    ---
    þ Synchronet þ Shadow River - shadowriver.homeip.net
  • From Deuce@VERT/SYNCNIX to Cyclops on Tuesday, April 04, 2006 17:03:00
    Re: Seaching Strings
    By: Cyclops to All on Tue Apr 04 2006 02:51 pm

    How does one do a simple string search in js?

    I want to get a simple true/false answer with if string1 is inside string2 at any position in the string

    If string1 is a literal, you can do this:
    (string2.search(/string1/)==-1)

    Otherwise...
    (string2.search(new RegExp(string1))==-1)



    ---
    This sig is not directed at Jazzman.

    ---
    þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Cyclops@VERT/SRBBS to Deuce on Tuesday, April 04, 2006 20:48:00
    If string1 is a literal, you can do this:
    (string2.search(/string1/)==-1)

    Otherwise...
    (string2.search(new RegExp(string1))==-1)

    Ok, so it is a literal, and if string2 is part of an object, the same applies right?

    I should be able to do...

    if(ojb.string2.search(/string1/)==-1

    That would be if string1 is NOT found right?

    What are the //'s for? Are they saying that string1 is literal?

    ---
    þ Synchronet þ Shadow River - shadowriver.homeip.net
  • From Deuce@VERT/SYNCNIX to Cyclops on Wednesday, April 05, 2006 20:55:00
    Re: Re: Seaching Strings
    By: Cyclops to Deuce on Tue Apr 04 2006 08:48 pm

    Ok, so it is a literal, and if string2 is part of an object, the same applies right?

    I should be able to do...

    if(ojb.string2.search(/string1/)==-1

    As long as it can be coerced into a string, yes.

    That would be if string1 is NOT found right?

    What are the //'s for? Are they saying that string1 is literal?

    It's a shorthand method of expressing a regexp.


    ---
    This sig is not directed at Jazzman.

    ---
    þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)