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

Modify long (html) string

Former Member
0 Likes
380

Dear All,

I would like to ask you for help in the following case. I have done number of trials but did not succeed.

I would like to amend long HTML string

Basically within the string I would like to replace the following part:

<bee:html><th align="left"></bee:html>#          <htmlb:textViewdesign="EMPHASIZED" text="Subindustry"/>#        <bee:html></th></bee:html>#

<bee:html><th/></bee:html>#

With

<bee:html><th align="left"></bee:html>#          <htmlb:textViewdesign="EMPHASIZED" text="Subindustry"/>#        <bee:html></th></bee:html>#

<bee:html><th align="left"></bee:html>#             <htmlb:textView design="EMPHASIZED" text="Attribute"/>#                   <bee:html></th></bee:html>

I.e. I need to add the underlined part.

Would anyone give me some hint how to approach this? As e.g. Replace command does not work due to special characters.

Many thanks,

Jan

1 REPLY 1
Read only

Former Member
0 Likes
337

Regular expression can be used in this case.

Basically we can put regex [^<]* which means all consecutive characters not equaling <.

Try running below code.

  1. DATA lv TYPE string.
  2. CONCATENATE lv '<bee:html><th align="left"></bee:html>' INTO lv.
  3. CONCATENATE lv '#   ' INTO lv.
  4. CONCATENATE lv '<htmlb:textViewdesign="EMPHASIZED" text="Subindustry"/>' INTO lv.
  5. CONCATENATE lv '#   ' INTO lv.
  6. CONCATENATE lv '<bee:html></th></bee:html>' INTO lv.
  7. CONCATENATE lv '#   ' INTO lv.
  8. CONCATENATE lv '<bee:html><th></bee:html>' INTO lv.
  9. DATA lv_regex TYPE string.
  10. CONCATENATE lv_regex '(' INTO lv_regex.
  11. CONCATENATE lv_regex '<bee:html><th align="left"></bee:html>' INTO lv_regex.
  12. CONCATENATE lv_regex '[^<]*' INTO lv_regex.
  13. CONCATENATE lv_regex '<htmlb:textViewdesign="EMPHASIZED" text="Subindustry"/>' INTO lv_regex.
  14. CONCATENATE lv_regex '[^<]*' INTO lv_regex.
  15. CONCATENATE lv_regex '<bee:html></th></bee:html>' INTO lv_regex.
  16. CONCATENATE lv_regex ')' INTO lv_regex.
  17. DATA lv_repl TYPE string.
  18. CONCATENATE lv_repl '$1' INTO lv_repl.
  19. CONCATENATE lv_repl '<bee:html><th align="left"></bee:html>' INTO lv_repl.
  20. CONCATENATE lv_repl '<htmlb:textView design="EMPHASIZED" text="Attribute"/>' INTO lv_repl.
  21. CONCATENATE lv_repl '<bee:html></th></bee:html>' INTO lv_repl.
  22. REPLACE REGEX lv_regex  IN lv WITH lv_repl.
  23. WRITE😕 lv.

//