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: 

shift string1 by 3 places right.

Former Member
0 Kudos
6,229

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

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
1,000

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

3 REPLIES 3

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
1,001

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

0 Kudos
1,000

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

manuel_bassani
Contributor
0 Kudos
1,000

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