参考 http://www.cplusplus.com/reference/string/string/
std::string::substr
string substr (size_t pos = 0, size_t len = npos) const;
Generate substring
Returns a newly constructed
string object with its value initialized to a copy of a substring of this object.
The substring is the portion of the object that starts at character position pos and spans len characters (or until the end of the string, whichever comes first).
Parameters
- pos
-
Position of the first character to be copied as a substring
.字串里将被复制的第一个字符的位置
If this is equal to the string length , the function returns an empty string.
If this is greater than the string length , it throws out_of_range .
Note: The first character is denoted by a value of 0 (not 1 ).
- len
-
Number of characters to include in the substring (if the string is shorter, as many characters as possible are used).
A value of string::npos indicates all characters until the end of the string. -
将被包含在字串里的字符数量
size_t is an unsigned integral type (the same as member type string::size_type ).
Return Value
A string object with a substring of this object.Example
|
|
String operations :
- c_str
- Get C string equivalent (public member function )
- data
- Get string data (public member function )
- get_allocator
- Get allocator (public member function )
- copy
- Copy sequence of characters from string (public member function )
- find
- Find content in string (public member function )
- rfind
- Find last occurrence of content in string (public member function )
- find_first_of
- Find character in string (public member function )
- find_last_of
- Find character in string from the end (public member function )
- find_first_not_of
- Find absence of character in string (public member function )
- find_last_not_of
- Find non-matching character in string from the end (public member function )
- substr
- Generate substring (public member function )
- compare
- Compare strings (public member function )
c++没有substring 查了几个博客还有写substring的