// // // // Substr // // Takes two int arguments, // // An int for the starting index, // // An int for the number of chars to return. // // Returns a MyString with the requested sub-string //// from the original MyString // // throws an exception if startIndex + numChars > Length() MyString MyString::SubStr(int startIndex, int numChars) const { if(startIndex + numChars > _length) { throw "Error: Index out of range."; } MyString tempStr; tempStr.Clear(numChars); //char *tempStr = new char [numChars + 1]; int tempIndex = 0; for(int i = startIndex; tempIndex < numChars; i++) { tempStr._string[tempIndex] = _string[i]; tempIndex++; } tempStr._string[numChars] = '\0'; return tempStr; }