Skip to Content
author's profile photo Former Member
Former Member

shift string1 by 3 places right.

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Aug 03, 2005 at 04:54 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

  • Posted on Aug 03, 2005 at 04:56 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.