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 unwanted chars from a string

0 Likes
605

hi friends,

mi special requirement is this:

i have a string containing:

"Jose[12] M[36]ller" and i only want to see [12][36] afterwards, so how could i remove the remaining characters ?

Thank you!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
577

Hi Clemens,

if u only want the data enclosed in the parentheses[] along with the parentheses then this program will work fine for you. Check the same and get back to us. If u can elaborate ur reqmt then we can help in a better way.

REPORT zyh284_test2.

DATA:

w_string TYPE string VALUE 'Jose[12] M[36]ller',

w_sub_string TYPE string,

w_int TYPE i,

w_char,

w_counter TYPE i,

fl_flag.

w_int = STRLEN( w_string ).

w_counter = 0.

DO w_int TIMES.

w_char = w_string+w_counter(1).

IF w_char EQ '['.

fl_flag = 'X'.

ENDIF.

IF fl_flag = 'X'.

CONCATENATE w_sub_string w_char INTO w_sub_string.

ENDIF.

IF w_char EQ ']'.

CLEAR fl_flag.

ENDIF.

w_counter = w_counter + 1.

ENDDO.

WRITE:w_sub_string.

3 REPLIES 3
Read only

Former Member
0 Likes
577

Hi,

Just paste the following code, I hope this solves your Query.

data :

w_char(30) value 'Jose[12] M[36]ller',

w_copy like w_char,

w_off type i,

w_length type i.

w_length = strlen( w_char ).

do w_length times.

if w_char+w_off(1) CN sy-abcde

and w_char+w_off(1) CN 'abcdefghijklmnopqrstuvwxyz'.

concatenate w_copy w_char+w_off(1) into w_copy.

endif.

add 1 to w_off.

enddo.

write w_copy.

Regards,

sandhya

Read only

Former Member
0 Likes
578

Hi Clemens,

if u only want the data enclosed in the parentheses[] along with the parentheses then this program will work fine for you. Check the same and get back to us. If u can elaborate ur reqmt then we can help in a better way.

REPORT zyh284_test2.

DATA:

w_string TYPE string VALUE 'Jose[12] M[36]ller',

w_sub_string TYPE string,

w_int TYPE i,

w_char,

w_counter TYPE i,

fl_flag.

w_int = STRLEN( w_string ).

w_counter = 0.

DO w_int TIMES.

w_char = w_string+w_counter(1).

IF w_char EQ '['.

fl_flag = 'X'.

ENDIF.

IF fl_flag = 'X'.

CONCATENATE w_sub_string w_char INTO w_sub_string.

ENDIF.

IF w_char EQ ']'.

CLEAR fl_flag.

ENDIF.

w_counter = w_counter + 1.

ENDDO.

WRITE:w_sub_string.

Read only

0 Likes
577

Thank you, this is just great and does as by my requirement!

Clemens