Conditional formatting of text using wildcards in Crystal Reports
Crystal Reports recognizes the *
as a wild card in like comparisons.
From some CR documentation available online:
Like pattern operator Basic and Crystal syntax.
The Like operator is useful for selecting records to include or exclude from your report.
Usage x like y
{fieldname} like "c?n*"
This operator tests to see if the contents of {fieldname} matches a pattern that you specify in a character string "c?n*". If the contents of the field do fit the pattern "c?n*", then the formula returns the value True. If the field starts with anything else, the formula returns False.
Use the wildcard symbols ? and * to stand for variable characters. The ? stands for a single character. The * symbol stands for any number of characters.
Examples The following examples are applicable to both Basic and Crystal syntax:
{customer.FIRST NAME} like "D?n"
TRUE, where {customer.FIRST NAME} = Dan or Don.
{customer.FIRST NAME} like "D?n"
FALSE, where {customer.FIRST NAME} = Doug or Rob.
{customer.LAST NAME} like "s?n"
TRUE, where {customer.LAST NAME} = Johnson or Olson or Olsen.
{customer.LAST NAME} like "s?n"
FALSE, where {customer.LAST NAME} = Johnston or Smith.
Shah
Updated on June 04, 2022Comments
-
Shah over 1 year
I need to write a conditional formatting where a text should be italic if it starts with " X". Otherwise it should be normal font.
How do I achieve string compare with wildcard? I tried the following:
IF({my_sp.field_label} like ' X%') then crItalic else crRegular
Any pointers will be appreciated!
-
Shah almost 11 yearsThanks a lot for the explanation!
-
Shah almost 11 yearsso if i do {fieldname} like " X?" it should be true for " X", " X12345", correct?
-
dotjoe almost 11 yearsno the
?
is a wildcard for a single character. so it'd be false for both examples. The*
is a wild card for 0 or more characters, so that'd be true forlike " X*"