_start = start; // Proper type conversion
- if (_start >= strlen(p->s) || _start + len >= strlen(p->s))
+ if (_start > strlen(p->s) || _start + len > strlen(p->s))
{
throw StringException("Substring Out of bounds: ("
+ String(start) + ", " + String(len) + ")");
std::cout << "The substring (3,5) of " << s1 << " is " << s2 << "\n";
assert(s2 == "defgh");
+ // Select a substring at the end of the string
+ s1 = "abcdefghijkl";
+ s2 = s1(6,6); // s2 = "ghijkl"
+
+ std::cout << "The substring (6,6) of " << s1 << " is " << s2 << "\n";
+ assert(s2 == "ghijkl");
+
String s3 = "abcdefghijkl";
String s4 = "12345678";
The substring (3,5) of abcdefghijkl is defgh
+The substring (6,6) of abcdefghijkl is ghijkl
Replace substring (3,5) of abcdefghijkl with 12345678 : abc12345678ijkl
Insert "12345678" into "abcdefghijkl" : abc12345678defghijkl
Remove part of "abc12345678defghijkl" : abc12345678ijkl