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: 

Need help in replacing special characters in a string

Former Member
0 Kudos

Hi,

please let me know the best way to replace all the special characters in a string with space.

other than alphabets and numbers

with regards.

sumanth.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hii

try using

loop at itab into wa_itab.

   replace all occurrences of 
    cl_abap_char_utilities=>CR_LF in wa_itab-field1 with space. 
modify itab from wa_itab index sy-tabix.

endloop.

reagrds

twinkal

9 REPLIES 9

Former Member
0 Kudos

check with this fm may be useful.

SCP_REPLACE_STRANGE_CHARS

former_member181995
Active Contributor
0 Kudos

Press F1 on TRANSLATE keyword and read the documentation for USING PATTERN option.

Former Member
0 Kudos

hii

try using

loop at itab into wa_itab.

   replace all occurrences of 
    cl_abap_char_utilities=>CR_LF in wa_itab-field1 with space. 
modify itab from wa_itab index sy-tabix.

endloop.

reagrds

twinkal

Former Member
0 Kudos

Hi,

Try this Function Module.

EFG_REPLACE_STRING

Former Member
0 Kudos

actually i need to replace hexa decimal char 0X1A in a string.... that is 'substitue' as per the chart

any pointers....

chk the link for the ASCII codes

http://www.techonthenet.com/ascii/chart.php

0 Kudos
please let me know the best way to replace all the special characters in a string with space.
other than alphabets and numbers

>

> actually i need to replace hexa decimal char 0X1A in a string.... that is 'substitue' as per the chart

> any pointers....

>

> chk the link for the ASCII codes

> http://www.techonthenet.com/ascii/chart.php

But in Hexa decimal value there is no special characters?

Former Member
0 Kudos

Hi,

Use like this

Example:

Data : lv_field type Char50 value 'abcd,:ad'.

data : lv_special_chars type char50 value '' ' _ < > ! " & / = + : , - ( ) # @ % ^ $ | ~'.

translate lv_field using lv_special_chars.

former_member705122
Active Contributor
0 Kudos

Show code.

Former Member
0 Kudos

*Try bellow codes


REPORT ztest.

DATA: ln TYPE i,
      cp TYPE p,
      fc TYPE char1,
      moff TYPE i.
CONSTANTS: stxt TYPE string VALUE '0123456789abcdefghijklmnopqrstuvwxyz'.


PARAMETERS: txt TYPE char20.

*start of selection
CONDENSE txt.
ln = STRLEN( txt ).
DO ln TIMES.
  fc = txt+cp(1).
  FIND fc IN stxt IGNORING CASE .
  IF sy-subrc NE 0.
    REPLACE ALL OCCURRENCES OF fc IN txt WITH space.
  ENDIF.
  ADD 1 TO cp.

ENDDO.
WRITE txt.