Tuesday, May 14, 2013

Envision string manupulation

String manipulation using square brackets [ ] takes two arguments.

X.STRING[x, y] where x is the starting position of the character, and y is the number of characters we want starting from x. If x is not provided, the position will be set to the end of the string, and counts backward.

X.STRING = '123456789'
X.STR1 = X.STRING[1,2]       -      X.STR1 = '12'
X.STR2 = X.STRING[1]          -      X.STR2 = '9'
X.STR3 = X.STRING[2]          -      X.STR3 = '8'
X.STRING[1,1] = 'FOO'          -      X.STRING = 'F23456789'
X.STR4 = X.STRING[1,2]       -      X.STR4 = 'F2'
X.STRING[1,2] = 'BAR'          -       X.STRING = 'BA3456789'

No comments:

Post a Comment