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

string manipulation

former_member215107
Active Participant
0 Likes
833

Hello,

i have srings like this:

string1 = "TOTO MR"

string2= "TITI S"

string3= "TATA DR"

How can i proceed to supress " MR", " S", " DR" to these strings.

Thanks for your help.

Rodolphe.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
800

Hi

Try using the SPLIT coomand.

Regards,

Arun

7 REPLIES 7
Read only

Former Member
0 Likes
801

Hi

Try using the SPLIT coomand.

Regards,

Arun

Read only

0 Likes
800

hi

Sample coding

string1 = 'TOTO MR' .

string2 = 'TITI S'.

string3 = 'TATA DR'.

split string1 at space into string4 string5.

split string1 at space into string4 string6.

split string1 at space into string4 string7.

concatenate string5 string6 string7 into lv_final.

write : LV_final.

Press F1 on split and concatenate for more details

Edited by: dharma raj on Jan 12, 2010 3:10 PM

Edited by: dharma raj on Jan 12, 2010 3:11 PM

Read only

Former Member
0 Likes
800

Hi,

We can try like this.



REPLACE ALL OCCURRENCES OF ' MS'  IN STRING1 BY '''.

Note: 1. There is one space before MS

2. BY '' where '' does not contain any character in between.

Regards,

Amit Mittal.

Read only

Former Member
0 Likes
800

Hi,

try this:


DATA: ST1 TYPE STRING VALUE 'TOTO MR'.
DATA: DUM TYPE STRING.
*
SPLIT ST1 AT 'MR' INTO: ST1 DUM.
*

Regards, Dieter

Read only

former_member215107
Active Participant
0 Likes
800

Thanks a lot.

Read only

Former Member
0 Likes
800

DATA: LENGTH TYPE I,

REMAINING_LENGTH TYPE I ,

NEXT_POINTER TYPE I ,

FIRST_HALF(20) TYPE C ,

SECOND_HALF(20) TYPE C ,

TEMP TYPE I .

string1 = "TOTO MR"

LENGTH = STRLEN( string1 ).

SEARCH string1 FOR ' '.

IF SY-SUBRC = 0 .

IF SY-FDPOS > 0.

MOVE string1+0(SY-FDPOS) TO FIRST_HALF.

ENDIF.

TEMP = SY-FDPOS + 1.

IF TEMP <> LENGTH.

NEXT_POINTER = SY-FDPOS + 1.

REMAINING_LENGTH = ( LENGTH - SY-FDPOS ) - 1.

MOVE string1+NEXT_POINTER(REMAINING_LENGTH) TO SECOND_HALF.

ENDIF.

ENDIF.

WRITE:/'Input String:', string1

.

WRITE:/'First Half:', FIRST_HALF.

WRITE:/'Second Half:', SECOND_HALF.

Do the same for rest of the strings.

Read only

0 Likes
800

Here the user enters the string from selection screen randomly.

DATA: LENGTH TYPE I,

REMAINING_LENGTH TYPE I ,

NEXT_POINTER TYPE I ,

FIRST_HALF(20) TYPE C ,

SECOND_HALF(20) TYPE C ,

TEMP TYPE I .

PARAMETER: string1(100) TYPE C . "INPUT WORD

Start-of-selection.

LENGTH = STRLEN( string1 ).

SEARCH string1 FOR ' '.

IF SY-SUBRC = 0 .

IF SY-FDPOS > 0.

MOVE string1+0(SY-FDPOS) TO FIRST_HALF.

ENDIF.

TEMP = SY-FDPOS + 1.

IF TEMP LENGTH.

NEXT_POINTER = SY-FDPOS + 1.

REMAINING_LENGTH = ( LENGTH - SY-FDPOS ) - 1.

MOVE string1+NEXT_POINTER(REMAINING_LENGTH) TO SECOND_HALF.

ENDIF.

ENDIF.

WRITE:/'Input String:', string1

.

WRITE:/'First Half:', FIRST_HALF.

WRITE:/'Second Half:', SECOND_HALF.