Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: String Question

  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    193
    Thanks
    147
    Thanked 0 Times in 0 Posts

    String Question

    Hello,

    I need your help.

    How could I write a functional if statement such that it would check against a series of various word strings seperated by commas ie.

    function check(y) {

    //y = "FOR INPUT"

    var string_to_check = FOR INPUT, FOR ACTION, FOR APPROVAL

    if (y isin string_to_check) { return 1 }

    }

    Thanks for everyones help.

    J

  • #2
    New Coder
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe setting up arrays with multiple string values and compare that to a array

  • #3
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Check indexOf and see if it is something other than -1

    If so, then the string you are searching for does exist in your list of possible values.

    It would look about like this:
    Code:
    function check(y){
    	//y = "FOR INPUT"
    	var string_to_check = "FOR INPUT,FOR ACTION,FOR APPROVAL";
    	if(string_to_check.indexOf(y)!=-1){
    		return true;
    	}
    	return false;
    }
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    jason_kelly (03-19-2012)

  • #4
    Regular Coder
    Join Date
    Sep 2011
    Posts
    193
    Thanks
    147
    Thanked 0 Times in 0 Posts
    Awesome work Rowsdower!

    Works like a charm.

    Thank you sooooooooo much.

    Cheers and have a great day!

    J


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •