on 11-19-2004 3:27 PM
I have a string that I read from a database that sometimes occurs special characters (e.g. HexCode A0). I'd like to remove all occurances of that character from the string.
I couldn't get "REPLACE" to work with HexCodes.
What can I do?
thx
Did you put in addition IN BYTE MODE?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The following example worked for me. I had to use the debugger to get the special characters into my test string. If you are worried about Unicode, this should work in a Unicode system as well (assuming that your input string is Unicode). I am taking your A0 hex and replacing it with 20 (space).
DATA: hex1(1) TYPE x VALUE 'A0'.
DATA: hex2(1) TYPE x VALUE '20'.
DATA: uhex1(2) TYPE x VALUE '00A0'.
DATA: uhex2(2) TYPE x VALUE '0020'.
DATA: char1(1) TYPE c.
DATA: test_string TYPE string VALUE 'Stuff in here'.
DATA: test_xstring TYPE xstring.
****Convert the Character String to Binary String
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = test_string
IMPORTING
buffer = test_xstring.
IF cl_abap_char_utilities=>charsize = 1.
REPLACE ALL OCCURENCES OF hex1 IN test_xstring WITH hex2 IN BYTE MODE.
ELSE.
REPLACE ALL OCCURENCES OF uhex1 IN test_xstring WITH uhex2 IN BYTE MODE.
ENDIF.
CLEAR test_string.
DATA:
convin TYPE REF TO cl_abap_conv_in_ce.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
input = test_xstring
RECEIVING
conv = convin.
CALL METHOD convin->read
IMPORTING
data = test_string.
WRITE: / test_string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
Have you tried casting the both the string as well as the value to Characters using field symbols.
Then I believe REPLACE would work.
To achieve the required casting Using assing with Casting.
Regards,
Pavan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
If I understand u problem correctly, you read a character string from database which sometimes has characters with hex code '0A' displayed as '#' which you would like to replace.
Now try this:
v1 is the string
v2 type x value '0A'.
field-symbols: <f2> type c.
assign v2 to <f2> casting.
replace all occurrences of <f2> in v1 with space.
You may have some problem doing this assignment sometimes, if so declare v2 as v2(4) type x value '0A'.
Now change the replace as
replace all occurrences of <f2>+0(1) in v1 with space.
Hope this helps.
Pavan
replace characters by ' '/ Space.
1. Get the string lenght of ur field
wf_datalen = strlen( <String> ).
2. DO wf_datalen TIMES.
wf_pos = sy-index - 1.
wf_char = <String>+wf_pos.
IF wf_char CN
'BCDEFGHIJKLMNOPQRSTUVWXYZ 123456789' &
'abcdefghijklmnopqrstuvwxyz+-*/=~#^()[]\&%$@.,;:"!'.
wf_dataline+wf_pos(1) = Space.
ENDIF.
Enddo.
I have removed A & 0(Zero) from the above. So that it will be replaced by space in your case.
Regards,
Prabhu Rajesh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You might also have a look at function module SCP_REPLACE_STRANGE_CHARS. It might work for what you are wanting to do.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.