Home | Index | universal Index | gsp Index | Examples | Tutorial

String Class Reference

#include "universal__String.h"

This class offers a set of low and high-level operations for safe and convenient handling of character strings, including commonly used operators (==,=. More...


Inherited Class(es)


Public Functions

String ( ) 
String ( const char * lpszSource , long iLen = -1 ) 
String ( const String & rStr 
String ( char 
String ( unsigned char 
String ( int iValue , const char * lpszFormat = 0 ) 
String ( unsigned int uValue , const char * lpszFormat = 0 ) 
String ( long iValue , const char * lpszFormat = 0 ) 
String ( unsigned long uValue , const char * lpszFormat = 0 ) 
String float fSource , const char * lpszFormat = 0 ) 
String double dSource , const char * lpszFormat = 0 ) 
operator const char * ( ) const 
~String ( ) 
append ( const char * pzStr 
append ( const String & rStr 
append ( char 
append ( unsigned char 
append ( unsigned int uN 
append ( int iN 
append ( unsigned long uN 
append ( long iN 
append float fN 
append double dN 
  • unsigned long 
capacity ( void ) const 
  • const char & 
charAt ( unsigned long uIndex ) const 
  • const char & 
charAt ( long iIndex ) const 
  • char & 
charAt ( unsigned long uIndex 
  • char & 
charAt ( long iIndex 
  • bool 
consistsOfChars ( const char * chararray ) const 
  • bool 
empty ( ) const 
  • bool 
endsWith ( const String & rStr ) const 
  • bool 
equals ( const char * pszStr ) const 
  • bool 
equals ( const String & rStr ) const 
  • bool 
equalsIgnoreCase ( const char * pszStr ) const 
  • bool 
equalsIgnoreCase ( const String & rStr ) const 
  • bool 
erase ( unsigned long start = 0 , int nb = -1 ) 
  • bool 
eraseRange ( unsigned long start , long end = -1 ) 
escapeSequence ( ) 
fill ( unsigned long uLen , char fillc = ' ' , unsigned long uFrom = 0xFFFFFFFF ) 
formatColumn ( unsigned long uColWidth 
grep ( const String & c_sSearch 
  • int 
hashCode ( ) const 
  • int 
indexOf ( int cha , unsigned long uStartFrom = 0 ) const 
  • int 
indexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
  • bool 
insert ( unsigned long uOffset , const String & rStr 
  • bool 
insert ( unsigned long uOffset , char 
  • bool 
isCaseLess ( ) const 
  • bool 
isUINT ( ) const 
justify ( unsigned long uColWidth 
  • int 
lastIndexOf ( int cha , unsigned long uStartFrom = 0 ) const 
  • int 
lastIndexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
left ( unsigned int uLength ) const 
  • unsigned long 
length ( void ) const 
  • bool 
matchesPattern ( const String & c_sPattern ) const 
  • bool 
matchesPattern ( const StringList & c_slPatternList ) const 
mid ( unsigned int uPosition , unsigned int uLength ) const 
nl ( const String & rStr 
operator ()( unsigned int uPosition , unsigned int uLength ) const 
  • char & 
operator []( int iIndex 
  • char & 
operator []( long iIndex 
  • char & 
operator []( unsigned int uIndex 
  • char & 
operator []( unsigned long uIndex 
  • const char & 
operator []( long iIndex ) const 
  • const char & 
operator []( int iIndex ) const 
  • const char & 
operator []( unsigned int uIndex ) const 
  • const char & 
operator []( unsigned long uIndex ) const 
operator =( char 
operator =( unsigned char 
operator =( const char * pszSource 
operator =( const String & rstrSource 
operator =( int iSource 
operator =( unsigned int uSource 
operator =( long lSource 
operator =( unsigned long uSource 
operator =( short sSource 
operator =( unsigned short usSource 
operator =float fSource 
operator =double dSource 
operator +=( const char * pszSource 
operator +=( const String & rstrSource 
operator +=( char 
operator +=( unsigned char 
operator +=( int iAdd 
operator +=( unsigned int iAdd 
operator +=( long lAdd 
operator +=( unsigned long uAdd 
operator +=float fAdd 
operator +=double dAdd 
operator +( const char * pszSource ) const 
operator +( const String & rstrSource ) const 
operator +( char ) const 
operator +( unsigned char ) const 
operator +( int iSource ) const 
operator +( unsigned int uSource ) const 
operator +( long lSource ) const 
operator +( unsigned long uSource ) const 
operator +float fSource ) const 
operator +double dSource ) const 
  • bool 
operator ==( const char * pszStr ) const 
  • bool 
operator ==( const String & rStr ) const 
  • bool 
operator ==( unsigned char ) const 
  • bool 
operator ==( char ) const 
  • bool 
operator ==( int iSource ) const 
  • bool 
operator ==( unsigned int uSource ) const 
  • bool 
operator ==( long lSource ) const 
  • bool 
operator ==( unsigned long uSource ) const 
  • bool 
operator ==float fSource ) const 
  • bool 
operator ==double dSource ) const 
  • bool 
operator !=( const char * pszStr ) const 
  • bool 
operator !=( const String & rStr ) const 
  • bool 
operator !=( unsigned char ) const 
  • bool 
operator !=( char ) const 
  • bool 
operator !=( int iSource ) const 
  • bool 
operator !=( unsigned int uSource ) const 
  • bool 
operator !=( long lSource ) const 
  • bool 
operator !=( unsigned long uSource ) const 
  • bool 
operator !=float fSource ) const 
  • bool 
operator !=double dSource ) const 
  • bool 
regionMatches ( bool ignoreCase , unsigned long utoffset , const String rStr , unsigned long uooffset , unsigned long uLen ) const 
  • bool 
replace ( char cOld , char cNew , bool bAll = false ) 
  • bool 
replace ( char cOld , const char * pszNew , bool bAll = false ) 
  • bool 
replace ( const char * pszOld , char cNew , bool bAll = false ) 
  • bool 
replace ( const char * pszOld , const char * pszNew , bool bAll = false ) 
reverse ( ) 
right ( unsigned int uLength ) const 
  • bool 
rubout ( const String & c_s , char cEraseChar = ' ' , unsigned long uFrom = 0 ) 
  • void 
set ( const char * pszValue 
  • void 
setCaseLess ( bool bCase = true ) 
  • void 
setEmpty ( ) 
shiftLeft ( unsigned long uHowMuch = 1 ) 
shiftRight ( unsigned long uHowMuch = 1 , char rightc = ' ' ) 
  • StringList 
split ( const String & c_sSep , bool bTrimItems = true ) const 
  • bool 
startsWith ( const String & rStr ) const 
  • const char * 
str ( ) const 
substring ( unsigned int uPosition , unsigned int uPositionEnd ) const 
toLowerCase ( void ) 
toString ( ) const 
toUpperCase ( void ) 
token ( char cSep 
token ( const String & rstrSep 
trim ( char = ' ' , bool bLessToo = false ) 
trimLeft ( char = ' ' , bool bLessToo = false ) 
trimRight ( char = ' ' , bool bLessToo = false ) 
untabify ( unsigned short usTabLen = 8 ) 
untabifyWithCursor ( unsigned long & uPos , unsigned short usTabLen = 8 ) 

Public Static Functions

formatOptionHelp String sOpt String sHelpText , unsigned long uOptColWidth = 30 , unsigned long uHelpColWidth = 40 , unsigned long uOptNbIndent = 2 ) 
  • bool 
toDouble ( const String & rStr double & rdTarget 
  • bool 
toFloat ( const String & rStr float & rfTarget 
  • bool 
toLong ( const String & rStr , long & rlTarget 
  • bool 
toString ( long lSource String & rRes 
  • bool 
toString ( unsigned long uSource String & rRes 
  • bool 
toString double rdSource String & rRes , int iPrecision = 10 ) 
  • bool 
toUnsignedLong ( const String & rStr , unsigned long & rulTarget 

Related Functions

operator +( const char * pszSource , const String & rStr 
  • bool 
operator <( const String & rStr1 , const String & rStr2 
  • bool 
operator >( const String & rStr1 , const String & rStr2 
  • std::ostream & 
operator <<( std::ostream & os , const String & rStr 

Related Types


Detailed Description

This class offers a set of low and high-level operations for safe and convenient handling of character strings, including commonly used operators (==,=...) and conversion functions to numeric types.

The strings are managed like conventional C-style null-terminated ASCII strings (char *). Input or output const char* values are therefore always assumed to be null-terminated. If not so, the results are undefined.

The cast operator to const char* is useful for getting the raw C-style string.

Some of the functions are also compatible with the handling of binary buffers, even if these buffers may contain null or non-printable chars. This peculiarity is always documented for the matching functions.

This class is especially optimised for high performance and combines internally static and dynamic memory buffering. A string instance always holds a deep and private copy of its string. String instances never share memory buffers.


Files Included

#include <vector>
#include "universal.h"

Functions Documentation

void ensureCapacity ( unsigned long uMinCapacity   [  protected  ] 

Memory Buffer management function.

Re-allocates the buffer if necessary to ensure that at least uMinCapacity are allocated

If the bufffer must be re-allocated, by default the new size is (old_size+1)*2. Otherwise it is uMinCapacity.

Selects the static or dynamic buffer according to the required size.

See also:

Back to index

String ( ) 

Default void constructor.

Constructs an empty string.

Example:

 String s; // s == ""

See also:

Back to index

String ( const String & rStr 

Copy constructor.

Constructs a copy of the passed rStr string.

Example:

 String s("Michel");
 String s2(s);  // s2 == "Michel"

See also:

Back to index

String ( const char * pszSource , long iLen 

Constructs a string which copies the iLen first chars of pszSource.

If the size iLen is unspecified (< 0), the whole input string is copied till end of string is encountered (\0).

This function is compatible with the handling of binary buffers. If a length is specified, the string will store the iLen bytes of the passed buffer, inclusive all null and non-printable chars. The value of the buffer can then be got back using the str() operation.

In all cases, the string is ended with a null char.

iLen is optional, by default iLen = -1.

See also:

const char * str ( ) const 
Back to index

Example:

 String s("Michel");  // s == "Michel"
 String s2("Michel", 2);  // s2 == "Mi"

String ( char 

Constructs a string which just contains c.

See also:

Back to index

String ( unsigned char 

Constructs a string which just contains c.

See also:

Back to index

String ( int iValue , const char * lpszFormat 

Constructs a string holding the string represention of int iValue.

lpszFormat is optional and contains the conversion format as given in in ::printf().

If lpszFormat is not specified (lpszFormat = NULL by default), operator=() is used for the conversion (safe). Otherwise, ::sprintf() with the specified formation is used (not safe).

Note:

This function is not recommended wherever safety is critical. When ::sprintf() is used, a limited buffer of size 100 is used. Moreover There is no consistency check made between the format and the passed value to convert.

See also:

String & operator =( int iSource 
static bool toString ( long lSource String & rRes 
Back to index

String ( unsigned int uValue , const char * lpszFormat 

Behaves like the above function but takes unsigned int uValue as argument.

Note:

Please read the notes of the first referenced function.

See also:

String ( int iValue , const char * lpszFormat = 0 ) 
String & operator =( unsigned int uiSource 
static bool toString ( unsigned long uSource String & rRes 
Back to index

String ( long iValue , const char * lpszFormat 

Behaves like the above function but takes long iValue as argument.

Note:

Please read the notes of the first referenced function.

See also:

String ( int iValue , const char * lpszFormat = 0 ) 
String & operator =( long lSource 
static bool toString ( long lSource String & rRes 
Back to index

String ( unsigned long uValue , const char * lpszFormat 

Behaves like the above function but takes unsigned long uValue as argument.

Note:

Please read the notes of the first referenced function.

See also:

String ( int iValue , const char * lpszFormat = 0 ) 
String & operator =( unsigned long uSource 
static bool toString ( unsigned long uSource String & rRes 
Back to index

String float fSource , const char * lpszFormat 

Behaves like the above function but takes float fValue as argument.

Note:

Please read the notes of the first referenced function.

See also:

String ( int iValue , const char * lpszFormat = 0 ) 
String & operator =float fSource 
static bool toString double rdSource String & rRes , int iPrecision = 10 ) 
Back to index

String double dSource , const char * lpszFormat 

Behaves like the above function but takes double dValue as argument.

Note:

Please read the notes of the first referenced function.

See also:

String ( int iValue , const char * lpszFormat = 0 ) 
String & operator =double dSource 
static bool toString double rdSource String & rRes , int iPrecision = 10 ) 
Back to index

~String ( )   [  virtual  ] 

Destructor.

Delete any memory allocated on the heap and resets pointers to null.

See also:

Back to index

int hashCode ( ) const 

Returns a hashcode for the string.

See also:

Back to index

bool empty ( void ) const 

Tells whether the string is empty (zero char).

See also:

Back to index

unsigned long length ( void ) const 

Returns the length of the string (0 or positive value).

See also:

Back to index

unsigned long capacity ( void ) const 

Returns the actual buffer capacity of the string (at least as great than the string length).

See also:

Back to index

int getChars ( int srcBegin , int srcEnd , char * dst , int dstBegin ) const   [  protected  ] 

Copies the chars between positions srcBegin and srcEnd to the target char array dst, starting at position dstBegin. The char of index "srcEnd" is not included !

See also:

Back to index

void setChars ( const char * pszSource , unsigned long uSrcLen , unsigned long uDstBegin   [  protected  ] 

Copies the chars from pszSource to this string, starting at position uDstBegin. Ensures the string has enougth capacity.

See also:

Back to index

const char * str ( ) const 

Returns the raw const char* pointer to the string buffer. The string can't be modified using the pointer. It is read-only.

See also:

Back to index

void set ( const char * pszValue 

Equivalent to operator=() but does not return a reference to itself.

Example:

  String s;
  s.set("Dog"); // s == "Dog"

See also:

String & operator =( const char * pszSource 
void setEmpty ( ) 
Back to index

void setEmpty ( ) 

Empties string (zero char). length() returns zero after that. Is equivalent to set("").

See also:

Back to index

void setCaseLess ( bool bCaseLess 

Sets this string as case less or not depending on bCaseLess. bCaseLess is optional and true by default.

This will be taken into account within any search and comparison functions.

See also:

Back to index

bool isCaseLess ( ) const 

Tells whether the string is case less.

See also:

Back to index

String & operator =( const char * pszSource 

Assigns the string to pszSource. pszValue must end with '\0' (end of string). Previous string value is lost and overwritten by a copy of pszSource.

Returns a reference to itself.

Example:

  String s;
  s = "Dog"; // s == "Dog"

See also:

void setEmpty ( ) 
void set ( const char * pszValue 
String & operator =( const String & rstrSource 
Back to index

String & operator =( const String & rStr 

Assigns the value of the passed string to this one. In all cases, the number of bytes copied is always that number returned by length() of the passed string.

This function is compatible with the handling of binary buffers. The passed string may contain a binary buffer for which length() returns the size.

Example:

  String s("Dog");
  String s2;
  s2 = s; // s2 == "Dog"

See also:

String & operator =( const char * pszSource 
unsigned long length ( void ) const 
Back to index

String & operator =( char 

Equivalent to the function referenced below, except that it takes a char as argument. After this operator, the string will just hold the passed char.

Example:

  String s;
  s = 'c'; // s == "c"

See also:

String & operator =( const char * pszSource 
Back to index

String & operator =( unsigned char 

Equivalent to the function referenced below.

See also:

String & operator =( char 
Back to index

String & operator =( int iSource 

Assigns the string to the string representation of the passed int iSource. The conversion function mentioned below is used to realise the conversion.

Example:

  String s;
  int i = 345;
  s = i; // s == "345"
  i = -1;
  s = i; // s == "-1"

See also:

void setEmpty ( ) 
static bool toString ( long lSource String & rRes 
Back to index

String & operator =( unsigned int uiSource 

Equivalent to the function mentioned above, except that it takes unsigned int uiSource as argument and that the conversion function used is the one mentioned below.

See also:

void setEmpty ( ) 
static bool toString ( long lSource String & rRes 
static bool toString ( unsigned long uSource String & rRes 
static bool toString double rdSource String & rRes , int iPrecision = 10 ) 
Back to index

String & operator =( long lSource 

Equivalent to the function mentioned above, except that it takes long lSource as argument and that the conversion function used is the one mentioned below.

See also:

void setEmpty ( ) 
static bool toString ( long lSource String & rRes 
Back to index

String & operator =( unsigned long uSource 

Equivalent to the function mentioned above, except that it takes unsigned long uSource as argument and that the conversion function used is the one mentioned below.

See also:

void setEmpty ( ) 
static bool toString ( unsigned long uSource String & rRes 
Back to index

String & operator =float fSource 

Equivalent to the function mentioned above, except that it takes float fSource as argument and that the conversion function used is the one mentioned below.

See also:

void setEmpty ( ) 
static bool toString double rdSource String & rRes , int iPrecision = 10 ) 
Back to index

String & operator =double dSource 

Equivalent to the function mentioned above, except that it takes double dSource as argument and that the conversion function used is the one mentioned below.

See also:

void setEmpty ( ) 
static bool toString double rdSource String & rRes , int iPrecision = 10 ) 
Back to index

String & operator =( short sSource 

Equivalent to the function mentioned above, except that it takes short sSource as argument and that the conversion function used is the one mentioned below.

See also:

void setEmpty ( ) 
static bool toString ( long lSource String & rRes 
Back to index

String & operator =( unsigned short usSource 

Equivalent to the function mentioned above, except that it takes unsigned short usSource as argument and that the conversion function used is the one mentioned below.

See also:

void setEmpty ( ) 
static bool toString ( unsigned long uSource String & rRes 
Back to index

String & reverse ( ) 

Inverts the chars of the string.

Returns a reference to itself.

Example:

  String s = "Reverse";
  s.reverse(); // s == "esreveR"

See also:

Back to index

String & toUpperCase ( ) 

Uppers case of string.

Returns a reference to itself.

Example:

  String s = "Upper";
  s.toUpperCase(); // s == "UPPER"

See also:

String & toLowerCase ( void ) 
Back to index

String & toLowerCase ( ) 

Lowers case of string.

Returns a reference to itself.

Example:

  String s = "LoWer";
  s.toLowerCase(); // s == "lower"

See also:

String & toUpperCase ( void ) 
Back to index

String & trimLeft ( char , bool bLessToo 

Removes all starting c. By default c = ' ' (space char).

bLessToo is optional. It tells whether all chars whose ASCII value is less than c shall also be removed. By default it is not the case.

Returns a reference to itself.

Example:

  String s = "   My sentence.  ";
  s.trimLeft(); // s == "My sentence."

See also:

String & trimRight ( char = ' ' , bool bLessToo = false ) 
String & trim ( char = ' ' , bool bLessToo = false ) 
Back to index

String & trimRight ( char , bool bLessToo 

Removes all ending c chars. By default c = ' ' (space char).

bLessToo is optional. It tells whether all chars whose ASCII value is less than c shall also be removed. By default it is not the case.

Returns a reference to itself.

Example:

  String s = "  My sentence.  ";
  s.trimRight(); // s == "  My sentence."

See also:

String & trimLeft ( char = ' ' , bool bLessToo = false ) 
String & trim ( char = ' ' , bool bLessToo = false ) 
Back to index

String & trim ( char , bool bLessToo 

Removes both all starting and ending c chars. By default c = ' ' (space char).

bLessToo is optional. It tells whether all chars whose ASCII value is less than c shall also be removed. By default it is not the case.

Returns a reference to itself.

Relies on trimLeft() and trimRight().

Example:

  String s = "  My sentence.  ";
  s.trim(); // s == "My sentence."

See also:

String & trimLeft ( char = ' ' , bool bLessToo = false ) 
String & trimRight ( char = ' ' , bool bLessToo = false ) 
Back to index

String & untabifyWithCursor ( unsigned long & uPos , unsigned short usTabLen 

Replaces any tabulation char by usTabLen space chars. usTabLen is optional. By default usTabLen = 8.

Additionally, this function computes the new position in the result string of the char that was initially at position uPos in the string. The new position is returned in uPos.

Returns a reference to itself.

Example:

  String s = "Name:\tMehl";
  unsigned long uPos = 6;
  s.untabifyWithCursor(uPos); // s == "Name:        Mehl"  uPos = 13.

See also:

String & untabify ( unsigned short usTabLen = 8 ) 
Back to index

String & untabify ( unsigned short usTabLen 

Behaves like the function referred to below, except that it does not manage a char position conversion. s.trim(); // s == "My sentence."

Example:

  String s = "Name:\tMehl";
  s.untabifyWithCursor(4); // s == "Name:    Mehl"

See also:

String & untabifyWithCursor ( unsigned long & uPos , unsigned short usTabLen = 8 ) 
Back to index

String & escapeSequence ( ) 

Replaces any character that can't be represented as is in a C string constant with the matching escape sequence.

The following table gives the correspondence between the chars and their escape sequence.

simple quote ' => \'

double quote " => \"

backslash \ => \\

horizontal tab => \t"

new line => \n

vertical tab => \v

backspace => \b

carriage return => \r

formfeed => \f

audible alert => \a

question mark => \?

octal number => \ooo

hexadecimal number => \xhh

See also:

Back to index

bool replace ( const char * pszOld , const char * pszNew , bool bAll 

Replaces string pszOld with pszNew.

All occurrences are replaced only if the optional parameter bAll is true, . By default bAll = false and only one occurrence is replaced.

This function is case sensitive.

Returns true is something was replaced, false otherwise.

Example:

  String s = "This is a integer";
  s.replace("is", "ee", true); // s == "Thee ee a integer"

See also:

Back to index

bool replace ( char cOld , char cNew , bool bAll 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it replaces a char with another char.

See also:

bool replace ( const char * pszOld , const char * pszNew , bool bAll = false ) 
Back to index

bool replace ( char cOld , const char * pszNew , bool bAll 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it replaces a char by a string.

See also:

bool replace ( const char * pszOld , const char * pszNew , bool bAll = false ) 
Back to index

bool replace ( const char * pszOld , char cNew , bool bAll 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it replaces a string with a char.

See also:

bool replace ( const char * pszOld , const char * pszNew , bool bAll = false ) 
Back to index

bool insert ( unsigned long uOffset , const String & rStr 

Inserts string rStr at uOffset. The chars inclusive char at uOffset are shifted to the right.

Returns true if insertion was successful. False if uOffset is invalid.

Example:

  String s = "This is a integer";
  s.insert(9, "n unsigned"); // s == "This is an unsigned integer"

See also:

bool insert ( unsigned long uOffset , char 
Back to index

bool insert ( unsigned long uOffset , char 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it just permits to insert a char.

See also:

bool insert ( unsigned long uOffset , const String & rStr 
Back to index

String & shiftLeft ( unsigned long uHowMuch 

Shifts the string uHowMuch times to the left. The uHowMuch first chars are lost.

uHowMuch is optional. Its default value is 1.

Relies on the function referred to below.

Returns a reference to itself.

Example:

  String s = "Complete String";
  s.shift(9); // s == "String"

See also:

bool erase ( unsigned long start = 0 , int nb = -1 ) 
Back to index

String & shiftRight ( unsigned long uHowMuch , char rightc 

Shifts the string uHowMuch times to the right setting the inserted uHowMuch first chars to rightc.

uHowMuch is optional. Its default value is 1. rightc is optional. Its default value is ' '.

Relies on the two last functions referred to below.

Returns a reference to itself.

Example:

  String s = "Complete String";
  s.shift(7); // s == "       Complete String"

See also:

String & String::shiftLeft ( unsigned long uHowMuch 
String & String::fill ( unsigned long uLen , char fillc 
bool String::insert ( unsigned long uOffset , const String & rStr 
Back to index

String & fill ( unsigned long uLen , char fillc , unsigned long uFrom 

Fills the string with uLen char(s) fillc.

fillc is optional. By default fillc = ' '.

uFrom is optional and set to 0xFFFFFFFF by default. In that case, the filling chars are appended to the current string.

If uFrom is specified, the filling chars overwrite the uLen first chars from position uFrom and overflowing chars are appended to the current string.

This function is compatible with the handling of binary buffers. The string can be filled with any byte value inclusive all null and non-printable chars. The value of the buffer can then be got back using the str() operation.

Returns a reference to itself.

Example:

  String s = "Original String";
  s.fill(9); // s == "Original String         "

See also:

Back to index

bool eraseRange ( unsigned long start , long end 

Removes chars between whose offset is between start and end. The char of offset end is not removed.

end is optional. By default end = -1 which means that all chars starting from start offset until the end of the string are removed.

Returns true if the removal was successful, false in those cases:

end is negative and is not -1, start or end is an invalid offset, start > end.

Note:

This function assumes that the string length is not greater than the maximum value of a long. Otherwise this function returns false.

Example:

  String s = "Original String";
  s.eraseRange(6,8); // s == "Origin String"

See also:

bool erase ( unsigned long start = 0 , int nb = -1 ) 
Back to index

bool erase ( unsigned long start , int nb 

Removes nb chars from index start.

nb is optional. By default nb = -1 which means that all chars until the end of the string are removed.

Returns true if the removal was successful, false in those cases:

nb is negative and is not -1, start + nb is greater that the string length.

Equivalent to eraseRange(start, (long)(start+nb))

Note:

This function assumes that the string length is not greater than the maximum value of a long. Otherwise this function returns false.

Example:

  String s = "Original String";
  s.erase(6,2); // s == "Origin String"

See also:

bool eraseRange ( unsigned long start , long end = -1 ) 
Back to index

bool rubout ( const String & c_s , char cEraseChar , unsigned long uFrom 

Rubs off string c_s and replace the empty space with cEraseChar chars.

In constrast with the erase() function, this function does not modify the string size. It just replaces any occurrence of c_s with as many cEraseChar needed to rub off c_s from the string.

It is much less time-consuming than other functions like erase() or replace() as no memory allocation and freeing is needed at all. Therefore it may sometimes be a better choice with regard to the result or the performance sought.

cEraseChar is optional and is the space char by default.

uFrom is optional and set to 0 by default. It gives the char index relative to c_s from which the erasing should actually take place. If the uFrom is greater than the size of c_s, nothing is done!

As return value, tells whether the string was changed.

Example:

 String s = "Original String";
 s.rubout("Original"); // s == "         String"
 s.rubout("Str", ' ', 1); // s == "         S  ing"

See also:

bool replace ( const char * pszOld , const char * pszNew , bool bAll = false ) 
bool erase ( unsigned long start = 0 , int nb = -1 ) 
Back to index

String & nl ( const String & rStr 

Appends string rStr terminated with a new line char. Convenient when generating lines of source code files for example.

Returns a reference to itself.

Example:

  String s = "Begin";
  String s2 = "End";
  s.append(s2).escapeSequence(); // s == "BeginEnd\n"

See also:

Back to index

String & append ( const String & rStr 

Appends string rStr.

Returns a reference to itself.

Example:

  String s = "Begin";
  String s2 = "End";
  s.append(s2); // s == "BeginEnd"

See also:

Back to index

String & append ( const char * pzStr 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it takes directly a C string (const char*) instead of a String object as parameter.

See also:

String & append ( const String & rStr 
Back to index

String & append ( char 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it just appends c.

See also:

String & append ( const String & rStr 
Back to index

String & append ( unsigned char 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it just appends unsigned c.

See also:

String & append ( const String & rStr 
Back to index

String & append ( unsigned int uN 

Appends the string representation of the passed unsigned int uN.

Returns a reference to itself.

Note:

Constructor String(unsigned int) is used for conversion.

Example:

  String s = "rfc";
  unsigned int i = 1913;
  s.append(i); // s == "rfc1913"

See also:

String & append ( const String & rStr 
Back to index

String & append ( int iN 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed int iN.

Note:

Constructor String(int) is used for conversion.

See also:

String & append ( unsigned int uN 
Back to index

String & append ( unsigned long uN 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed unsigned long uN.

Note:

Constructor String(unsigned long) is used for conversion.

See also:

String & append ( unsigned int uN 
Back to index

String & append ( long iN 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed long iN.

Note:

Constructor String(long) is used for conversion.

See also:

String & append ( unsigned int uN 
Back to index

String & append float fN 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed float fN.

Note:

Constructor String(float) is used for conversion.

See also:

String & append ( unsigned int uN 
Back to index

String & append double dN 

Overloaded function provided for convenience. Behaves like the function referred to below, except that it appends the string representation of the passed double dN.

Note:

Constructor String(double) is used for conversion.

See also:

String & append ( unsigned int uN 
Back to index

String & operator +=( const char * pszStr 

Overloaded function provided for convenience. Behaves like the function referred to below.

See also:

String & append ( const char * pzStr 
Back to index

String & operator +=( const String & rStr 

Overloaded function provided for convenience. Behaves like the function referred to below.

See also:

String & append ( const String & rStr 
Back to index

String & operator +=( char 

Overloaded function provided for convenience. Behaves like the function referred to below.

See also:

String & append ( char 
Back to index

String & operator +=( unsigned char 

Overloaded function provided for convenience. Behaves like the function referred to below.

See also:

String & append ( unsigned char 
Back to index

String & operator +=( int arg 

Overloaded function provided for convenience. Behaves like the function referred to below.

See also:

String & append ( int iN 
Back to index

String & operator +=( unsigned int arg 

Overloaded function provided for convenience. Behaves like the function referred to below.

See also:

String & append ( unsigned int uN 
Back to index