• Seaching Strings

    From Cyclops@VERT/SRBBS to All on Tue Apr 4 10:51:00 2006
    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 Tue Apr 4 13:03:00 2006
    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 Tue Apr 4 16:48:00 2006
    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 Wed Apr 5 16:55:00 2006
    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!)