Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting text within a string

Status
Not open for further replies.

waldopepper

Programmer
Nov 21, 2003
124
GB
I have a text field that would read a lot easier if I could conditionally highlight certain words within it.

Basically I am printing out selection logic and I want to color/bold etc the logical operators so that:

(selection1 OR selection2) AND selection3

would read as

(selection1 OR selection2) AND selection3

Or even a background color to the text would be better. Is any of this possible?
 
All of it is possible, the solution being Crystal version dependent, something that you should share with any post if you want good answers (1st thing any tech support person would ask you for almost any product).

I'll assume that this text field is a string field from the database, and not a text object in Crystal:

Crystal supports HTML formatting, so use a replace function in a formula to replace the OR and AND with red:

So instead of the field, use a formula:

replace(replace({table.field},'OR,'
<font color=&quot;red&quot;> OR </font>','and','
<font color=&quot;red&quot;> AND </font>')

Place the formula, right click it and select format field->font->paragraph->HTML

(going from memory assuming CR 8.5 or greater as I don't have CR installed right now)

-k
 
Oh yeh, I have CR9.
Thanks for the solution - I see where you're going but I think there's a problem with where the quotation marks are - CR complains when I try and save it.

??
 
Hmmm, I was worried about that...

Try eliminating the quotes around RED

Otherwise we might parse the text into formulas and handle it, but that'll get kinda ugly if it's potentially a lot of text.

-k
 
Since SV doesn't have his CR to test, I'll help out. The following gives you the color:

replace(replace({table.field},&quot;OR&quot;,
&quot;<font color=red>&quot;+&quot;OR&quot;+&quot;</font color>&quot;),&quot;AND&quot;,
&quot;<font color=red>&quot;+&quot;AND&quot;+&quot;</font color>&quot;)

If you are using this for a specific string, you could use the following to get the bold and the color:

&quot;(selection1 &quot;+&quot;<b>&quot;+&quot;<font color = red>&quot;+&quot;OR&quot;+&quot;</font color>&quot;+&quot;</b>&quot;+&quot; selection2) &quot;+&quot;<b>&quot;+&quot;<font color = red>&quot;+&quot;AND&quot;+&quot;</font color>&quot;+&quot;</b>&quot;+&quot; selection3&quot;

Be sure to use HTML paragraph formatting (format field->paragraph->text interpretation->HTML).

-LB
 
Awesome, this works great and I didn't know about rendering html in Crystal at all until now. Thanks for the info guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top