2011 Aug 30 7:05 PM
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?
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
2011 Aug 30 7:25 PM
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
2011 Aug 30 7:35 PM
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
2011 Aug 30 7:35 PM
2023 Oct 05 3:16 PM
Thank you very much. It solved the problem I had in Longtext.
2011 Aug 30 11:01 PM
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
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |