[SOLVED] Substring(i,j) Error OpenHAB2

I am getting a substring error. Can the documentation possibly be wrong?
My example is :
var String Template = “SMTWTFS 12:34 999”
var String MyString = “SMTWTFS 12:34 999”
var Number MyLength = 0

MyString = Template.substring(2,5)
MyLength = MyString.length()

As I understand the documentation, the string 1st character is position 0 and MyString should contain characters 2, 3, 4, and 5; i.e. “TWTF” however it does not. It contains “TWT” and MyLength = 3. I’ve tried adding characters via

MyString = MyString + “123”

to verify there is not an issue with a string termination character but there is not.

I get “TWT123” with MyLength = 6.

Any help will be appreciated.
…bob

From the docs

Parameters:

beginIndex - the beginning index, inclusive.

endIndex - the ending index, exclusive.

The endIndex is exclusive so you need to add one more to it to get the F.

Thank you Rich. I read many threads as I try to work through problems because of my lack of knowledge. I regularly read your help messages to those in trouble. Thanks for all you do.
…bob