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

shift string1 by 3 places right.

Former Member
0 Likes
7,610

code ->

data: string1(10) type c value 'abcdefghij',
      string2 like string1.

write:  / 'Before Manipulations : ',
        / 'string1 = ',string1,
        / 'string2 = ',string2.

string2 = string1.
shift string1.

write : / 'after one shift first letter is gone :-) (leftShift)',
          ' ', string1.

write : / 'after the shift operation there is a permanent change in',
          'the field value of string1'.
shift string1 by 3 places right.

write : / 'after shifting 3 places on the right-', string1,
        / 'DOUBT - only ij has gone, but hij should have gone right ?'.
        


write : / 'string2 also has same as string1 had initially-', string2.

shift string2 by 3 places right.

write : / 'after shifting 3 places on the right-', string2.

Doubt has been marked in the code itself. This is my first post. Please do explain me concept , in the above code,if i am wrong.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,381

To answer you question, no because a space was the third character.

After your initial shift, "A" has been removed, which has added a space to the end of the 10 chanacter field. Then shifting right 3 places would get rid of the space, then the "J", then the "I".

If this answer was helpful, please remember to award points accordingly. Thanks.

Regards,

Rich Heilman

code ->

data: string1(10) type c value 'abcdefghij',
      string2 like string1.

write:  / 'Before Manipulations : ',
        / 'string1 = ',string1,
        / 'string2 = ',string2.

string2 = string1.
shift string1.

write : / 'after one shift first letter is gone :-) (leftShift)',
          ' ', string1.

write : / 'after the shift operation there is a permanent change in',
          'the field value of string1'.
shift string1 by 3 places right.

write : / 'after shifting 3 places on the right-', string1,
        / 'DOUBT - only ij has gone, but hij should have gone right ?'.
        


write : / 'string2 also has same as string1 had initially-', string2.

shift string2 by 3 places right.

write : / 'after shifting 3 places on the right-', string2.

Doubt has been marked in the code itself. This is my first post. Please do explain me concept , in the above code,if i am wrong.

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,382

To answer you question, no because a space was the third character.

After your initial shift, "A" has been removed, which has added a space to the end of the 10 chanacter field. Then shifting right 3 places would get rid of the space, then the "J", then the "I".

If this answer was helpful, please remember to award points accordingly. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
2,381

It works in STRING2 because you never did an initial shift to the left.

If you did want this to work in the string... you would have to find out the length of the string and then shift on that offset.

data: stlen type i.

shift string2.

stlen = strlen( string2 ).

shift string2+0(stlen) by 3 places right.

Regards,

Rich Heilman

Read only

manuel_bassani
Contributor
0 Likes
2,381

Hi,

it is right that only ij is gone. Please consider the following:

Initially:

string1 = 'abcdefghj'

after shift string1:

string1 = 'bcdefghj ' (with trailing space)

after shift string1 by 3 places right:

string1 = ' bcdefg' (deletes ij and the space character)

Regards, Manuel