cancel
Showing results for 
Search instead for 
Did you mean: 

Replace space

FredericGirod
Active Contributor
0 Kudos

Hi,

I would like to replace each space characater by the ' ' code in a string.

(for HTML presentation)

I try to write a macro to make this job, but .. I'm not able to make it work.

Regards

Frédéric

Accepted Solutions (1)

Accepted Solutions (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You can do something like this.

report zrich_0003 .

data: this_string type string.


this_string = 'This is the string'.

while sy-subrc = 0.
  replace space with '&nbsp' into this_string.
endwhile.

write:/ this_string.

You could also use the statement instead of th WHILE loop...

REPLACE ALL Occurrences of space in this_string with '&nbsp'.

Regards,

Rich Heilman

FredericGirod
Active Contributor
0 Kudos

Hi Rich,

so, it's exactly what I would like to do, but SAP don't want .

When I use the replace all occurences, I have a dump :

REPLACE_INFINITE_LOOP

Rgd

Frédéric

Message was edited by: Frédéric Girod

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

<i>"This is the string" -> "This&nbsp;is&nbsp;the&nbsp;string"</i>

That is exactly what this code does..... Or am I missunderstanding you.

Regards,

Rich Heilman

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Oops, yes, I forgot. You need to specify the length.



report zrich_0003 .


data: this_string type string.
data: length type i.

this_string = 'This is the string'.

length = strlen( this_string ).


REPLACE ALL Occurrences of space in this_string+0(length) with ' '.

write:/ this_string.


Regards,

Rich Heilman

FredericGirod
Active Contributor
0 Kudos

Well done !

Thank you Rich.

Fred

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Yes, it results in dump, bcauz there is no terminating condition to come out of the loop ('all occurrences')

sorry guys, couldnt make translate work.

Try translate command.

Regards,

Raj

Message was edited by: Rajasekhar Dinavahi