substr — extract a portion of a string


string substr( str,  
string   str;
int   start;
int   end ;


Returns a specified sub section of the string str. The section returned is the section starting at character index start up to but not including character index end. If the optional parameter end is omitted then the entire string, starting at start, is returned. Note that character indices are zero based, so that substr(str, 0) == str.

The following conditions lead to undefined results, most likely runtime errors:

  • If either character index is out of range (i.e. less than zero or greater than the string length).
  • If start > end.

Example 52. substr Example

string str = substr("Hello, world!", 7, 12);    // = "world"