Report Bugs Here

Moderator: Mmiscool

User avatar
By cwilt
#37277 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"
User avatar
By TassyJim
#37281 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
User avatar
By cwilt
#37284
TassyJim wrote:right(msg,x) gives you the righmost x characters


If that is the way it should work then the documentation is wrong.
User avatar
By TassyJim
#37285
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