To shift the contents of a field, by one position or one character you can use the SHIFT statement. Using SHIFT allows you to shift field contents, byte-by-byte or character-by- character.
With the SHIFT statement, you can execute the following:
String = ‘HELLO’.
String 1 = ‘ALL OF YOU’.
String 2 = ‘WORK HARD’.
Shift string
Shift string1 by 2 places.
Shift string2 right.
Shift string1 by 2 places circular.
The output will be
ELLO – By default if nothing is specified then string is shifted by one position.
L OF YOU – Here the string is shifted by 2 places.
_WORK HARD – In this case the string is shifted to right by one place (with leading blanks)
K HARDWOR – In this case the string is shifted to the left so that 3 characters on the left appear on the right.
With the SHIFT statement, you can execute the following:
String = ‘HELLO’.
String 1 = ‘ALL OF YOU’.
String 2 = ‘WORK HARD’.
Shift string
Shift string1 by 2 places.
Shift string2 right.
Shift string1 by 2 places circular.
The output will be
ELLO – By default if nothing is specified then string is shifted by one position.
L OF YOU – Here the string is shifted by 2 places.
_WORK HARD – In this case the string is shifted to right by one place (with leading blanks)
K HARDWOR – In this case the string is shifted to the left so that 3 characters on the left appear on the right.
No comments:
Post a Comment