String
Description
This class stores information about a dynamically allocated sequence of wide (UTF-16) characters, used for textual data.
String class is implicitly convertible from C strings (char*
and wchar_t*
pointers) so String parameters can be easy specified as string constant or regular C string.
class String { public: static const int NPos = -1; typedef int SizeType; String(); String( const String& str ); explicit String( const wchar32* str ); explicit String( const wchar16* str ); String( const char* str ); String( const wchar_t* str ); String( int n, wchar16 c ); String( int n, char c ); String( int n, wchar_t c ); ~String(); int Size() const; int Length() const; int MaxSize() const; bool Empty() const; int Capacity() const; wchar16* Begin(); const wchar16* Begin() const; wchar16* End(); const wchar16* End() const; int Compare(const String& str ) const; void Swap( String& str ); wchar16& At(int index); const wchar16& At(int index) const; void Reserve( int newCapacity ); void Clear( void ); void PushBack( wchar32 c ); void PushBack( wchar16 c ); void PushBack( char c ); void PushBack( wchar_t c ); void Resize( int n, wchar32 c ); void Resize( int n, wchar16 c = 0 ); void Resize( int n, char c ); void Resize( int n, wchar_t c ); int Copy( wchar16* buff, int n, int Pos = 0 ) const; String& Erase( int pos = 0, int n = NPos ); String& Assign( const String& str ); String& Assign( const wchar32* str ); String& Assign( const wchar16* str ); String& Assign( const char* str ); String& Assign( const wchar_t* str ); String& Assign( wchar32 c ); String& Assign( wchar16 c ); String& Assign( char c ); String& Assign( wchar_t c ); String& Append( const String& rhs ); String& Append( const wchar32* str ); String& Append( const wchar16* str ); String& Append( const char* str ); String& Append( const wchar_t* str ); String& Append( wchar32 c ); String& Append( wchar16 c ); String& Append( wchar_t c ); String& Append( char c ); String& Insert ( int pos1, const String& str, int pos2, int n ); String& Insert ( int pos1, const String& str ); String& Insert ( int pos1, const char* s, int n); String& Insert ( int pos1, const char* s ); String& Insert ( int pos1, int n, char c ); String& Insert ( int pos1, const wchar_t* s, int n); String& Insert ( int pos1, const wchar_t* s ); String& Insert ( int pos1, int n, wchar_t c ); wchar16& operator[]( int index ); const wchar16& operator[]( int index ) const; bool operator== ( const String& str ) const; bool operator< ( const String& str ) const; bool operator<= ( const String& str ) const; bool operator> ( const String& str ) const; bool operator>= ( const String& str ) const; bool operator!= ( const String& str ) const; const String& operator += ( const String& rhs ); const String& operator += ( wchar_t c ); const String& operator += ( char c ); const String& operator += ( wchar16 c ); const String& operator += ( const wchar_t* str ); const String& operator += ( const char* str ); const String& operator = ( const String& str ); const String& operator = ( const wchar_t* str ); const String& operator = ( const char* str ); const String& operator = ( char c ); const String& operator = ( wchar_t c ); const wchar16* CStr16() const; const char* CStr8() const; String Substr( int pos = 0u, int len = NPos ) const; bool EndsWith( const atl::String& str ) const; bool EndsWith( const wchar32* str ) const; bool EndsWith( const wchar16* str ) const; bool EndsWith( const char* str ) const; bool EndsWith( const wchar_t* str ) const; bool StartsWith( const atl::String& str ) const; bool StartsWith( const wchar32* str ) const; bool StartsWith( const wchar16* str ) const; bool StartsWith( const char* str ) const; bool StartsWith( const wchar_t* str ) const; int Find( const atl::String& str, int pos = 0 ) const; int RFind( const atl::String& str, int pos = -1 ) const; String Strip( void ) const; #ifdef HAS_CPP0X String( String&& str ); String& Assign( String&& str ); const String& operator = ( String&& str ); #endif // HAS_CPP0X }; String operator+ ( const String& lhs, const String& rhs );
Methods:
int Length()
- returns number of characters in string.bool Empty()
- returnstrue
when string is empty (got zero length).int Compare( const String& str )
- compares (case sensitively) this string with another, return value is <0, 0, >0 according to strings relation.String Substr( int pos, int len )
- creates new String from subset of this String.bool EndsWith( const atl::String& str )
- determines if this string ends with specified characters sequence.bool StartsWith( const atl::String& str )
- determines if this string starts with specified characters sequence.
const wchar16* CStr16()
- returns C string with wide characters (UTF-16) as pointer to internal String buffer. This buffer will be valid up to next operation on String object or its destruction.const char* CStr8()
- returns C string (UTF-8) as pointer to internal String buffer. This buffer will be valid up to next operation on String object or its destruction.
Following operators can be used on String class:
==, <, !=
- for comparison with other String class.=
- for assigning content of other Strings, C strings or characters.+, +=
- for concatenation (appending) of other Strings, C strings or characters.