Common member function
< string>
std::string::substr
string substr (size_t pos = 0, size_t len = npos) const;
Produce substring
Returns a new one
A copy of the String object that is initialized to a substring of the String object.
The
substring is the part of the object that starts at character position pos and spans len characters (or up to the end of the string, whichever comes first).
parameter
-
The position of the first character is copied as a substring.
this function returns an empty string if this is equal to the length of the string.
if this is greater than the length of the string, it will throw out_of_range.
note: the first character is represented as the value 0 (not 1).
-
The number of characters included in the subscript (if the string is short, as many characters as possible can be used as needed).
string :: non-profit value represents all characters up to the end of the string.
pos
len
size_t is an unsigned integral type (the same as member type)
string::size_type).
The return value A
String Object with a substring of this object.
Example
|
|
Output:
think live in details. |