...

View Full Version : String Question



jason_kelly
03-19-2012, 03:25 PM
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

elhippie
03-19-2012, 03:43 PM
maybe setting up arrays with multiple string values and compare that to a array

Rowsdower!
03-19-2012, 03:51 PM
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:

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;
}

jason_kelly
03-19-2012, 03:59 PM
Awesome work Rowsdower!

Works like a charm.

Thank you sooooooooo much.

Cheers and have a great day!

J



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum