1. Home
  2. Docs
  3. Personalization
  4. Reference
  5. String Comparison Functions

String Comparison Functions

These string functions are for use in comparisons, primarily in <$if$> tags.

The functions are logical operators, so they are all of the form leftstring function rightstring, and are interpreted as we read them: left to right.

In all of the examples, string literals are used. However these will typically be custom fields in a real templating implementation e.g. <$if Name contains “phil”$>Hi, Phil<$endif$>. In addition, in a template, these functions would need to be inside an <$if$> or <$eval$> tag. These tags have been omitted from this page for clarity.

Important: all these functions are case insensitive.

contains

True (1) if the left string contains the right string at any point. So:

  • “phil” contains “philip” is false (0)
  • “Philip” contains “hil” is true (1)

notcontains

True (1) if the left string does not contain the right string at any point. So:

  • “phil” notcontains “philip” is true (1)
  • “Philip” notcontains “hil” is false (0)

startswith

True (1) if the left string starts with the right string. So:

  • “phil” startswith “philip” is false (0)
  • “Philip” startswith “hil” is false (0)
  • “Philip” startswith “phil” is true (1)

endswith

True (1) if the left string ends with the right string. So:

  • “phil” endswith “philip” is false (0)
  • “Philip” endswith “hil” is false (0)
  • “Philip” endswith “phil” is false (0)
  • “Philip” endswith “LIP” is true (1)

notstartswith

True (1) if the left string does not start with the right string. So:

  • “phil” notstartswith “philip” is true (1)
  • “Philip” notstartswith “hil” is true (1)
  • “Philip” notstartswith “phil” is false (0)

notendswith

True (1) if the left string does not end with the right string. So:

  • “phil” notendswith “philip” is true (1)
  • “Philip” notendswith “hil” is true (1)
  • “Philip” notendswith “phil” is true (1)
  • “Philip” notendswith “LIP” is false (0)