Products Downloads


French version


 

This function compares two alphanumeric strings.

Unlike lexicographic comparison which compares the coding value of each character, this comparison uses a collation which enables two character strings to be compared according to a given language.

It returns 0 if the two strings are the same (the comparison is case sensitive). It returns a value lower than 0 if the first string is strictly lower than the second. It returns a value higher than 0 if the first string is higher than the second.

Parameters

String

stringVal1

Alphanumeric string to compare

Mandatory

String

stringVal2

Alphanumeric string to compare

Mandatory

Hash

collatorInfos

Definition of collation information. This object can have the following attributes:

  • "locale": string in IETF BCP 47 format identifying a sort locale,
  • "strength": string representing the strength of the collation to determine the level of difference considered as significant in the comparisons. Five values are provided: "identical", "primary", "secondary", "tertiary" and "quaternary".
  • "decomposition": string representing the collation decomposition mode. It determines the processing of Unicode combining characters. Setting the decomposition mode enables the user to choose between a quicker and fuller classification behavior. Three values are provided: "no_decomposition", "canonical_decomposition" and "full_decomposition"

Optional.

If this object is not provided, the locale taken for the comparison is that entered for template execution ("strength" and "decomposition" attributes will have a default value which depends on the locale).

 


For example

<#assign stringVal1 = "foo" />
<#assign stringVal2 = "bar" />
<#assign compare = hardisCore.localeBasedCompareString(stringVal1, stringVal2) />
<#if compare == 0>
${stringVal1} equals ${stringVal2}
<#elseif compare > 0>
${stringVal1} is greater than ${stringVal2}
<#else>
${stringVal1} is less than ${stringVal2}
</#if> 

↑ Top of page