Substring documentation incorrect?

It looks like substring(from,to) is working more like substring(from, length).

I tested it like this

String str = “reflect1234”;
String sub = str.substring(0,7);
Serial.println(sub);

I get “reflect” when I’m expecting “reflect1”

Are the docs wrong?

Docs are perfectly right:

the starting index is inclusive (the corresponding character is included in the substring), but the optional ending index is exclusive (the corresponding character is not included in the substring).

substring(0,7) means exactly 7 characters starting from (and including) character number 0.

1 Like