Jump to content

rule that ignores initial caps or all-caps user input


Recommended Posts

Posted

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

Posted

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".

Posted
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?
Posted
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...