substr
Aus cppreference.com
< cpp | string | basic string
Syntax:
#include <string> string substr( size_type index = 0, size_type length = npos ) const;
Die substr Methode von Strings gibt einen Teilstring des aktuellen Strings zurück. Es beginnt bei index, mit einer Länge von length Zeichen.
Liegt index + length hinter dem Ende des Strings, so wird nur der Teil zwischen index und dem String-Ende zurück gegeben.
Fällt length weg, wird es zu string::npos, und substr wird das Ende des String zurückgeben, beginnend ab index.
Beispiel:
string s("What we have here is a failure to communicate"); string sub = s.substr(21); cout << "The original string is " << s << endl; cout << "The substring is " << sub << endl;
zeigt
The original string is What we have here is a failure to communicate
The substring is a failure to communicateVerwandte Themen: copy