Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Replace complete words by another string

Former Member
0 Likes
4,009

Hi,

I'm searching for a possibility to replace complete words inside a string.

For example I want to replace "quick" by "slow":

"The <b>quick</b> brown fox is running quicker then the slow brown fox".

The result shall be:

"The <b>slow</b> brown fox is running quicker then the slow brown fox".

The problem is, that the built in "Replace"-Method would also replace "quicker" by "browner".

Furthermore, words beetween different signs (e.g. , . ; : - ! " ? ') shall also be found as complete word.

I already searched for a FM but didn't find anything. Regular expressesions are also not possible because we are running on 6.40.

Maybe anybody can help me with a simple FM or something else.

Best regards,

Stefan

10 REPLIES 10
Read only

Former Member
0 Likes
2,036

Hi,

Try REPLACE ALL OCCURANCES OF statement.

Ashvender

Read only

0 Likes
2,036

Hi Ashvender,

as far as I know this would also replace all substrings, or not!?

Stefan

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
2,036

HI,

Can try with " quick ".

Regards,

Sesh

Read only

0 Likes
2,036

Hi Sesh,

that would work. But if there does occur another sign (such as quotes) it wouldn't work...

Stefan

Read only

0 Likes
2,036

Hi,

Then may be you can to execute multiple REPLACE statements.

I know its crude but I think no option.

Also may be you can split your string at SPACE and then

execute REPLACE in table.

Regards,

Sesh

Read only

Former Member
0 Likes
2,036

Hi,

Give the line in one string

IF string CN 'quick'.

REPLACE 'quick' WITH 'sloa' INTO field.

ENDIF.

Regards,

Nandha

Reward if it helps

Read only

Former Member
0 Likes
2,036

Hi Stefan,

There is a crude way of doing this....with lots of loops..

You can use the SPLIT statement

SPLIT dobj AT sep INTO

{ {result1 result2 ...} | {TABLE result_tab} }

[IN {CHARACTER|BYTE} MODE].

and break the sentence into words using space as delimiter. Once you have all the words in a internal table, you can loop through it and compare each word with the word you want.

This will solve the problem, but will not be performant enough.

Regards,

Vinodh

Read only

0 Likes
2,036

Hi,

your not replacing 'quick' your replacing ' quick '.

see this:

*----


REPORT ZEND_TEST14 MESSAGE-ID zrsp.

data: l_string type string value 'The quick brown fox is running quicker then the slow brown fox'..

replace ' quick ' in l_string with ' slow '.

write l_string.

*----


Steffen

Read only

Former Member
0 Likes
2,036

Use

REPLACE <'FIND TEXT'> IN <COMPLETE SEMNTENCE> WITH <'REPLACED TEXT'>.

or

replace all occurances of '.' with ''.

or

REPLACE '.' WITH ' ' INTO in_par-value.

or

var1 = '4444/33'.

REPLACE '/' with SPACE in var1.

Condense var1 no-gaps.

Rewards if useful.

Read only

0 Likes
2,036

Hi everybody,

I have played around with different possibilities but nothing seems to be really good. Insertion of space before and after the search-term is not possible because of many other signs which can precede or follow.

I think the only one solution at this time would be to try the different combinations of the "special signs" in combination with the word - but this could slow down the whole application.

I decided not to offer the possibility to replace whole words. Only simple replacements with "REPLACE" will be possible.

Best regards,

Stefan