bobk_IMbranded Posted October 14, 2010 Posted October 14, 2010 I have a graphic rule that allows a user to enter a name in a variable data field and if it matches a what I want it to, it'll return a graphic- - if (Field("Dealership Name").indexOf(String("Acura")) > -1) { return Resource("Acura.png"); but I want to allow for the possibility that a user may type in all caps or initial caps and or all lower case. As long as the it matches the words, I don't care about the case. How do I amend this rule to do that? also, what does that "> -1" mean in the first line? thanks -bob
esmith Posted October 15, 2010 Posted October 15, 2010 you could change your IF statement to if (Field("Dealership Name").toLowerCase().indexOf("acura") > -1) The toLowerCase method converts your field value to all lowercase which you compare to an all-lowercase string in your indexOf method. The indexOf method returns the start position of the string you're looking for in the string you're searching. A value of "-1" is returned if there is no match while a value of zero or greater is returned if the string does exist. So the code above is essentially saying "if the string exists anywhere in field value".
bobk_IMbranded Posted October 15, 2010 Author Posted October 15, 2010 Thanks Eric. That's a lot more straight forward than I expected.
bobk_IMbranded Posted October 15, 2010 Author Posted October 15, 2010 Eric, I forgot to ask about this..., I noticed you removed the "(String" portion of the rule after .indexOf(). Does leaving this in change the effect? What purpose does it have either way?
esmith Posted October 15, 2010 Posted October 15, 2010 String() is redundant in this case because anything between the parenthesis is automatically defined to be a string. Leaving it in is not "wrong"; just unnecessary.
bobk_IMbranded Posted October 15, 2010 Author Posted October 15, 2010 Thanks, that's what I thought. I tested it both ways and it all worked the same. Thanks for confirming!! -bob
Recommended Posts
Archived
This topic is now archived and is closed to further replies.