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

remove special chars from a string

Former Member
0 Likes
1,151

hi could anyone please advice me...how to remove special characters from a string...

thanks in advance..

4 REPLIES 4
Read only

Former Member
0 Likes
768

hi

chk the sample prog:

REPORT zstring.

DATA : ipstr TYPE string.

DATA : opstr TYPE string.

DATA : len TYPE i VALUE 0.

DATA : ch TYPE char1.

DATA : num TYPE i VALUE 0. "No of Characters to be taken

DATA : pos TYPE char3. "Position of Char in the Input String

*Input string

ipstr = '<FT><H><T> Line Clearance </></></>'.

*Removing only "</>"

REPLACE ALL OCCURRENCES OF '</>' IN ipstr WITH ' '.

*Removing only "<"

REPLACE ALL OCCURRENCES OF '<' IN ipstr WITH ' '.

CONDENSE ipstr.

*Length of Input String

len = STRLEN( ipstr ).

DO len TIMES.

*Char by Char

ch = ipstr+pos(1).

pos = pos + 1.

*Scan each char in input String for ">"

FIND '>' IN ch IGNORING CASE.

IF sy-subrc = 0.

num = len - pos.

*Output String

opstr = ipstr+pos(num).

ENDIF.

ENDDO.

WRITE 😕 opstr.

**reward if helpful

regards,

madhu

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
768

Hi,

<b>CP</b>

Covers Pattern: True, if the content of operand1 fits the pattern in operand2. Wildcard characters can be used for forming the operand2 pattern, where "" represents any character string, and "+" represents any character. Upper/lower case is not taken into account. If the comparison is true, sy-fdpos contains the offset of operand2 in operand1, whereby leading wildcard characters "" in operand2 are ignored if operand2 also contains other characters. If the comparison is false, sy-fdpos contains the length of operand1. You can select characters in operand2 for a direct comparison by adding the escape symbol "#" before the required characters. For these characters, upper/lower case is taken into account, wildcard characters and the escape symbol itself do not receive special treatment, and trailing blanks in operands of type c are not cut off.

DATA: str1 TYPE string,

str2 TYPE string.

str1 = 'ABCDEFGH'.

str2 = 'CF+H'.

IF str1 CP str2.

  • Use <b>Translate</b> keyword to remove the special characters by using space.

and after that use <b>Condense</b> .

Cheers,

Simha.

Reward all the helpful answers..

ENDIF.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
768

You can use the TRANSLATE statement or the REPLACE statement.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
768

hI..

data: w_text(50) type C value 'Ram?mohan?45jAGAN'.

data: w_len type i,

W_OFF TYPE I.

w_len = strlen( w_text ).

do w_len times.

W_OFF = SY-INDEX - 1.

if sy-abcde cs w_text+W_OFF(1).

else.

w_text+W_OFF(1) = SPACE.

ENDIF.

ENDDO.

CONDENSE W_TEXT.

WRITE : W_TEXT.