Problems with REPLACE


I am using the following formula in a report, to replace certain

if {Command.narrative} like '*format*' then replace({Command.narrative},'format',' ') else
if {Command.narrative} like '*nostock*' then replace({Command.narrative},'nostock',' ') else

The problem is that the first line of the formula works but the 2nd line doesn't i.e. it doesn't replace any words with nostock in with ''.

Any help would be appreciated
Who is Participating?
Ido MilletConnect With a Mentor Professor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
I suspect you wish to replace both words in a single field.
To do that, you can either nest the replace functions like this:
Replace(Replace({Command.narrative},'format',' '),'nostock',' ')

or use a string variable to hold the result, like this:

Stringvar result;
result := replace({Command.narrative},'format',' ');
replace(result ,'nostock',' ');
Another thing that might be happening is the case is an issue.

Replace(Replace({Command.narrative},'format',' ',,1),'nostock',' ',,1)

The 1 tells replace to do a non-case sensitive replace

Your method fails because you have the second test in the else clause so it is only tested for strings that don't have format in them.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.