Find a word and Replace in a Sentence

nandanak

New Member
I want to check a word in a sentence and replace.
Ex: The word : "aaaaaa bcd efg".

I want to check the word "efg" from this sentence and replace it from another word.
How can I do it in OpenEdge ?
 

vignesh

New Member
Hi,

Try this example,


DEFINE VARIABLE l_name AS CHARACTER format "x(30)" NO-UNDO.

l_name = "aaaaaa bcd efg".

l_name = replace(l_name,"efg","abc") .

DISPLAY l_name.
 

TomBascom

Curmudgeon
That will replace embedded "efg" as well as stand-alone words. If the original poster really wants "words" then the first problem is parsing the string into words. Try doing that with the text of this message. It's not so simple. You could start by treating it as a space delimited string and using ENTRY() to get chunks of text that might be words. Punctuation and line-feeds might be problems but it would be a start.
 

TomBascom

Curmudgeon
That will replace embedded "efg" as well as stand-alone words. If the original poster really wants "words" then the first problem is parsing the string into words. Try doing that with the text of this message. It's not so simple. You could start by treating it as a space delimited string and using ENTRY() to get chunks of text that might be words. Punctuation and line-feeds might be problems but it would be a start.
 
Top