-->
Page 1 of 2

Function right() bug

PostPosted: Sun Dec 27, 2015 6:57 pm
by cwilt
Function right() returns the string from the end position, not the start.

Example...
msg = "This is a test"
print right(msg,6)

returns "a test"

Re: Function right() bug

PostPosted: Sun Dec 27, 2015 9:06 pm
by TassyJim
Try this test:
Code: Select allmsg = "this_is_a_long_string_to_test"
short = left(msg,6)
print short
short = right(msg,6)
print short
short = mid(msg,6,3)
print short
short = mid(msg,6)
print short
print "All done!"
wait


left(msg,x) gives you the leftmost x characters
right(msg,x) gives you the righmost x characters
mid(msg,x,y) gives you the y most characters starting at position x.
mid(msg, x) gives you zero characters because y is zero. Other basics would give you the remainder of the string if y is omitted.

Code: Select allthis_i
o_test
is_

All done!


All lines are printed to the console but only the first two lines appear in the web interface!

Jim

Re: Function right() bug

PostPosted: Sun Dec 27, 2015 10:44 pm
by cwilt
TassyJim wrote:right(msg,x) gives you the righmost x characters


If that is the way it should work then the documentation is wrong.

Re: Function right() bug

PostPosted: Sun Dec 27, 2015 11:04 pm
by TassyJim
cwilt wrote:If that is the way it should work then the documentation is wrong.


I agree that the documentation needs improving.

If you want the right part of a string starting at position x and returning the remainder of the string, you can use
Code: Select allshort = mid(msg,6,99)
print short

where 99 is any number that is longer than the longest string.

Jim