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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Character String search 2

Status
Not open for further replies.

Harki06

Technical User
May 18, 2006
85
US
Hi,

I am using Crystal Reports 10. I have a memo field in the database SQL server.

The string can be somthing like this 'Customer requested $200. Paid customer $100. Case is resolved'. The field is Officecomments.

I want to search for every $ occurence and highlight it in some way on a report - either color or increased font. Is that possible?

Thanks!
 
Create a formula:

stringvar x := {table.memo};
numbervar i;
numbervar j := len(x);
stringvar y := "";

for i := 1 to j do(
if x = "$" or
isnumeric(x) then
y := y + "<font color = red>" + x else
if x = " " then
y := y + "<font color = black>" + x else
y := y + x
);
y

Place this on your report and right click on it->format field->paragraph->text interpretation: HTML Text. Also be sure to format it to "can grow" on the common tab.

-LB
 
Do you mean highlight each individual $ occurence within a field, or highlight the field if it has a $?

Is it just the $ you want highlighted or the $200?

LB supplied a method to highlight each $, although an array would be more efficient and accurate as you are keying off of the $ not any numeric, as in:

stringvar array input1 := split({table.field}," ");
numbervar j;
stringvar output:="";
for j := 1 to ubound(input1) do(
if "$" in input1[j] then
output := output + "<font color = red>" & input1[j] +" "
else
output := output + "<font color = black>" & input1[j] +" "
);
left(output,len(output)-1)

That handles each occurrnce within the text, if you want the entire field highlighted just use the formula next to the font color in the formatting of th field, as in;

if instr{table.field},"$") > 0 then
crred
else
crlack

-k
 
Thank you! I wanted the $ only highlighted since i dont know what the amount will be. It worked and I thank you very much - both of you! You guys are awesome!!!

This is what variation I did.
I created a formula DisplayComments which has the following statement -
Replace ({OfficeComments},"$","<font color=red>$</font>" ).

Then, on the formula field I used the HTML Text Interpretation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top