Comparing Two String Values
In many cases, you may wish to compare two string values, or to compare the value of a string parameter to a particular string. For example, you may wish to determine if the user entered the value such as Deluxe for the string parameter askSize.
To compare two string values:
• Define an expression for this parameter that evaluates the user’s response, such as: askSize.equals(“Deluxe”)
If the user enters the value Deluxe, it is stored in the parameter askSize and the expression is evaluated as true.
|
You cannot use a simple equals operator (=) because string values must be evaluated using Java methods (equals).
|
In some cases, you may have assigned a string value to a parameter to make it easier to manage multiple comparison expressions in a consistent manner. In this case, the expression would be:
askSize.equals(deluxeparameter)
where the default value of the string parameter deluxeparameter was defined as Deluxe.
|
To evaluate a string expression that contains one or more double quotes (“), you must identify, or escape, each double quote with a backslash (\) as shown in the following example:
myname.equals(“Robert \“Bob\” Smith”)
|