Application Development 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: 

Replacing hex characters problem

Former Member
0 Kudos

I have a text box where users can paste text into. When processing I notice a bunch of special characters.

To remove them, I am converting to Hex using

  
CALL METHOD cl_abap_codepage=>convert_to
    EXPORTING
      source      = iv_text
      codepage    = `UTF-8`
      replacement = ''
      ignore_cerr = abap_false
    RECEIVING
      result      = buffer.

Then I replace the special character posing as an apostrophe with the hex equivalant of an apostrophe.


  DATA:lv_old_ap TYPE x VALUE '99',
            lv_new_ap TYPE x VALUE '27',
  
  REPLACE ALL OCCURRENCES OF lv_old_ap IN buffer WITH lv_new_ap IN BYTE MODE .

Then convert it back to a string.


  CALL METHOD cl_abap_codepage=>convert_from
    EXPORTING
      source      = buffer
      codepage    = `UTF-8`
      replacement = ''
      ignore_cerr = abap_true
    RECEIVING
      result      = iv_text.

However, for some reason it's also inserting two spaces when converting the apostrophe.

Input text:

u201CI donu2019t have any skulls and crossbones on me.u201D

Output text:

u201CI don 't have any skulls and crossbones on me.u201D

Any idea why it's inserting two spaces?

5 REPLIES 5

Sandra_Rossi
Active Contributor
0 Kudos

Hi,

Could you provide us with the original hex value of iv_text please? (for the text you mentioned, do it with the debugger )

I would like to make sure about the original encoding (because 99 doesn't correspond to an apostrophe, so it is probably accompanied with something else)

Moreover, do you have a Unicode system?

Thx

Sandra

yes, we have a unicode system.

I just solved the issue by running the text through FM 'SCP_REPLACE_STRANGE_CHARS' instead of messing around with the hex replacement.

thanks for the help

Former Member
0 Kudos

used FM 'SCP_REPLACE_STRANGE_CHARS'

0 Kudos

Thank you very much. It solved the problem I had in Longtext.

Subhankar
Active Contributor
0 Kudos

Just use the statement

If you know the Hex value then use the below class to get the special char..

CL_ABAP_CONV_IN_CE =>UCCP

exporting

uccp = '00A0' " Hex value

receiving

char = buffer.

your replace statement need to change. like below

REPLACE ALL OCCURRENCES OF buffer IN lv_old_ap WITH lv_new_ap IN BYTE MODE .

Thanks

Subhankar