cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Replace string in field with new string

0 Likes
1,687

Hi. I'm a total newbie to Crystal reports, so don't be surprised if my question is very basic.


I'm trying to use a Replace function via the Select Expert's "Formula Workshop". There's a particular value that could occupy a field called "SPEC_RULE". The text that is normally there is not very descriptive, so I would like to use a more descriptive sentence in the report. I see the Replace function is available, but when I've tried to use it I haven't written it properly so far. For example, the "inputString", what is that supposed to be? Is it {MY_TABLE.SPEC_RULE}? When I've written Replace ({MY_TABLE.SPEC_RULE},"Unwanted string","Better string") it gives me an error saying, "The remaining text does not appear to be part of the formula." Here's an example of what I tried:

{PRODUCT.VERSION} = 2 and{PRODUCT_GRADE.VERSION} = 2{PRODUCT_SPEC.SPEC_RULE} = Replace ({PRODUCT_SPEC.SPEC_RULE},"Equal to","% Solids +/- 1 SD")

Accepted Solutions (1)

Accepted Solutions (1)

DellSC
Active Contributor
0 Likes

You have the Replace function set up correctly. However, the rest of your formula is not so Crystal doesn't know how to parse it. Do you need an "If..Then" like this:

If {PRODUCT.VERSION} = 2 and {PRODUCT_GRADE.VERSION} = 2 then
  Replace ({PRODUCT_SPEC.SPEC_RULE},"Equal to","% Solids +/- 1 SD")
else
  {PRODUCT_SPEC.SPEC_RULE}

Also, you can't set a field equal to a certain value. Instead, your formula will return the value you're looking for and you'll use the formula on the report instead of the field.

-Dell

0 Likes

Thanks, Christy. I actually rediscovered the formula field option just before I logged back in to the forum to check my messages. You're right, that's the way to go. Thanks again!

Answers (0)