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

String & operator +=( long arg 

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

See also:

String & append ( long iN 
Back to index

String & operator +=( unsigned long arg 

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

See also:

String & append ( unsigned long uN 
Back to index

String & operator +=float arg 

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

See also:

String & append float fN 
Back to index

String & operator +=double arg 

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

See also:

String & append double dN 
Back to index

String operator +( const char * arg ) const 

Provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

Example:

  String s = "I will go to swimmingpool";
  String s2 = s + " tomorrow";
  // s2 == "I will go to swimmingpool tomorrow"
  // s is unchanged.

See also:

String & append ( const char * pzStr 
Back to index

String operator +( const String & arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append ( const char * pzStr 
Back to index

String operator +( char arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append ( char 
Back to index

String operator +( unsigned char arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append ( unsigned char 
Back to index

String operator +( int arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append ( int iN 
Back to index

String operator +( unsigned int arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append ( unsigned int uN 
Back to index

String operator +( long arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append ( long iN 
Back to index

String operator +( unsigned long arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append ( unsigned long uN 
Back to index

String operator +float arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append float fN 
Back to index

String operator +double arg ) const 

Overloaded function provided for convenience. Performs the same action of the equivalent append() function, but constructs and returns the result in a new string object.

See also:

String operator +( const char * pszSource ) const 
String & append double dN 
Back to index

const char & charAt ( unsigned long uIndex ) const 

Behaves like the function mentionned below.

See also:

const char & operator []( unsigned long uIndex ) const 
Back to index

const char & charAt ( long iIndex ) const 

Behaves like the function mentionned below.

See also:

const char & operator []( long iIndex ) const 
Back to index

char & charAt ( unsigned long uIndex 

Behaves like the function mentionned below.

See also:

char & operator []( unsigned long ulIndex 
Back to index

char & charAt ( long iIndex 

Behaves like the function mentionned below.

See also:

char & operator []( long iIndex 
Back to index

char & operator []( unsigned int uIndex 

Returns a reference to the char at index uIndex. Modifying the returned char also modifies the char of the string. This operator is called when the application wants to get the char value and change it.

Example:

  String s = "Wood";
  char& cFirst= s[0] ; // cFirst == 'W'
  printf("First character of string is: '%c'. Now changing it.\n", cFirst);
  cFirst = 'G';  // Now s == "Good"
  printf("Also changing second character\n", cFirst);
  s[1] = 'G';    // Now s == "GGod"

See also:

Back to index

char & operator []( unsigned long uIndex 

Behaves like the above function but with an unsigned long index.

See also:

char & operator []( unsigned int uIndex 
Back to index

char & operator []( int iIndex 

Behaves like the above function except that it takes an int index and that for negative indexes the last char is returned.

See also:

char & operator []( unsigned int uIndex 
Back to index

char & operator []( long iIndex 

Behaves like the above function but with a long index.

See also:

char & operator []( int iIndex 
Back to index

const char & operator []( unsigned int uIndex ) const 

Returns the char at index uIndex. This operator is called when the application just wants to get the char value and not modify it.

Example:

  String s = "Welcome home";
  char cFirst= s[0] ; // cFirst == 'W'

See also:

Back to index

const char & operator []( unsigned long uIndex ) const 

Behaves like the above function but with an unsigned long index.

See also:

const char & operator []( unsigned int uIndex ) const 
Back to index

const char & operator []( int iIndex ) const 

Behaves like the above function except that it takes an int index and that for negative indexes the last char is returned.

See also:

const char & operator []( unsigned int uIndex ) const 
Back to index

const char & operator []( long iIndex ) const 

Behaves like the above function but with a long index.

See also:

const char & operator []( int iIndex ) const 
Back to index

String operator ()( unsigned int uPosition , unsigned int uLength ) const 

Equivalent to mid().

Example:

  String s = "Welcome home";
  String s2 = s(0,7) // s2 = "Welcome"

See also:

String mid ( unsigned int uPosition , unsigned int uLength ) const 
String left ( unsigned int uLength ) const 
String right ( unsigned int uLength ) const 
String substring ( unsigned int uPosition , unsigned int uPositionEnd ) const 
Back to index

String left ( unsigned int uLength ) const 

Returns the uLength leftmost chars.

If uLength is greater than the actual string length, an empty string is returned.

Otherwise it is equivalent to mid(0, uLength)

Example:

  String s = "Welcome home";
  String s2 = s.left(7) // s2 = "Welcome"

See also:

String mid ( unsigned int uPosition , unsigned int uLength ) const 
String right ( unsigned int uLength ) const 
String substring ( unsigned int uPosition , unsigned int uPositionEnd ) const 
String operator ()( unsigned int uPosition , unsigned int uLength ) const 
Back to index

String right ( unsigned int uLength ) const 

Returns the uLength rightmost chars.

If uLength is greater than the actual string length, an empty string is returned.

Otherwise it is equivalent to mid(length() - uLength, uLength)

Example:

  String s = "Welcome home";
  String s2 = s.right(4) // s2 = "home"

See also:

String mid ( unsigned int uPosition , unsigned int uLength ) const 
String left ( unsigned int uLength ) const 
String substring ( unsigned int uPosition , unsigned int uPositionEnd ) const 
String operator ()( unsigned int uPosition , unsigned int uLength ) const 
Back to index

String substring ( unsigned int uPosition , unsigned int uPositionEnd ) const 

Returns the sub-string of ending at uPositionEnd and starting from uPosition. The char at index uPositionEnd is not part of the returned string.

If uPosition >= uPositionEnd, an empty string is returned.

Otherwise it is equivalent to mid(uPosition, uPositionEnd-uPosition);

Example:

  String s = "Welcome home";
  String s2 = s.substring(2, 4) // s2 = "lc"

See also:

String mid ( unsigned int uPosition , unsigned int uLength ) const 
String left ( unsigned int uLength ) const 
String right ( unsigned int uLength ) const 
String operator ()( unsigned int uPosition , unsigned int uLength ) const 
Back to index

String mid ( unsigned int uPosition , unsigned int uLength ) const 

Returns the sub-string of length uLength starting from uPosition.

If uPosition is beyond the end of the string, an empty string is returned.

If uPosition + uLength is greater than the string length, only the substring until end of string is returned.

Example:

  String s = "Welcome home";
  String s2 = s.mid(8, 10) // s2 = "home"
  String s3 = s.mid(0, 8)  // s3 = "Welcome "

See also:

String left ( unsigned int uLength ) const 
String right ( unsigned int uLength ) const 
String substring ( unsigned int uPosition , unsigned int uPositionEnd ) const 
String operator ()( unsigned int uPosition , unsigned int uLength ) const 
Back to index

String grep ( const String & c_sSearch 

Performs the same operation as the famous grep unix command. Scans all the lines contained within the string and keep those containing the searched string.

Returns a string which results of the concatenation of all matching lines.

See also:

Back to index

String token ( const String & rstrSep 

Extracts and returns the string part at the left of rstrSep.

The separator string rstrSep is not extracted and is removed from the original string.

If rstrSep is not found, the whole string is extracted and returned and the string is emptied.

Relies on strstr().

Example:

  String s = "It#sep#is#sep#sunny";
  String s2 = s.token("#sep#") // s == "is#sep#sunny" and s2 == "It"
  String s3 = s.token("#sep#") // s == "sunny" and s2 == "It" and s3 == "is"

See also:

String token ( char cSep 
Back to index

String token ( char cSep 

Extracts and returns the string part at the left of cSep.

The separator char cSep is not extracted and is removed from the original string.

If no cSep is found, the whole string is extracted and returned and the string is emptied.

This specific function is available for performance purposes as it relies on ::strrchr().

Example:

  String s = "It is sunny";
  String s2 = s.token(' ') // s == "is sunny" and s2 == "It"
  String s3 = s.token(' ') // s == "sunny" and s2 == "It" and s3 == "is"

See also:

String token ( const String & rstrSep 
Back to index

StringList split ( const String & c_sSep , bool bTrimItems ) const 

Splits the string into the list of substrings which are separated by c_sSep.

bTrimItems is optional and tells whether to trim the extracted substrings.

See also:

String token ( const String & rstrSep 
Back to index

int indexOf ( int cha , unsigned long uStartFrom ) const 

Returns the offset of the first occurrence of cha beyond offset uStartFrom. Returns -1 if not found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0

This specific function is available for performance purposes as it relies on ::strrchr().

Example:

  String s = "NiceTown";
  s.indexOf('e';) // == 3

See also:

int indexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
int lastIndexOf ( int cha , unsigned long uStartFrom = 0 ) const 
int lastIndexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
Back to index

int indexOf ( const String & rStr , unsigned long uStartFrom , bool bIgnoreCase ) const 

Returns the offset of the first occurrence of rStr beyond offset uStartFrom. Returns -1 if no such substring is found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0 bIgnoreCase is optional. By default bIgnoreCase = false

Uses ::strstr().

This function assumes that the length of the string is not greater than the upper boundary value of a long.

Example:

  String s = "NiceTown";
  s.indexOf("Town"); // == 4
  s.indexOf("ow"); // == 5
  s.indexOf("Ah"); // == -1

See also:

int indexOf ( int cha , unsigned long uStartFrom = 0 ) const 
int lastIndexOf ( int cha , unsigned long uStartFrom = 0 ) const 
int lastIndexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
Back to index

int lastIndexOf ( int cha , unsigned long uStartFrom ) const 

Returns the offset of the last occurrence of cha beyond offset uStartFrom. Returns -1 if not found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0

This specific function is available for performance purposes as it relies on ::strrchr().

Example:

  String s = "NiceTown";
  s.lastIndexOf('e'); // == 3

See also:

int indexOf ( int cha , unsigned long uStartFrom = 0 ) const 
int indexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
int lastIndexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
Back to index

int lastIndexOf ( const String & rStr , unsigned long uStartFrom , bool bIgnoreCase ) const 

Returns the offset of the last occurrence of rStr beyond offset uStartFrom. Returns -1 if no such substring is found or if uStartFrom is greater than or equal to the string length. uStartFrom is optional. By default uStartFrom = 0 bIgnoreCase is optional. By default bIgnoreCase = false

This function assumes that the length of the string is not greater than the upper boundary value of a long.

Example:

  String s = "NiceTown";
  s.lastIndexOf("Town"); // == 4
  s.lastIndexOf("Tow"); // == 4
  s.lastIndexOf("Ah"); // == -1

See also:

int indexOf ( int cha , unsigned long uStartFrom = 0 ) const 
int indexOf ( const String & rStr , unsigned long uStartFrom = 0 , bool bIgnoreCase = false ) const 
int lastIndexOf ( int cha , unsigned long uStartFrom = 0 ) const 
Back to index

bool regionMatches ( bool bIgnoreCase , unsigned long utoffset , const String rStr , unsigned long uooffset , unsigned long uLen ) const 

Compares substring of length uLen starting at offset utoffset with the substring of rStr of the same length starting at offset uooffset. If bIgnoreCase is true, the char case is not taken into account. Returns false if utoffset + uLen is greater than the string or if uooffset + uLen is greater than the passed string length.

Example:

  String s = "NiceTown";
  String s2 = "cetoz";
  if (s.regionMatches(true, 2, s2, 0, 4)) // Success
  ...
  if (s.regionMatches(true, 2, s2, 0, 5)) // Failure
  ...

Note:

It is not tested whether utoffset + uLen > upperboundary(unsigned long) It is not tested whether uooffset + uLen > upperboundary(unsigned long)

See also:

bool operator ==( const String & rStr ) const 
bool operator !=( const String & rStr ) const 
bool equals ( const String & rStr ) const 
bool equalsIgnoreCase ( const String & rStr ) const 
Back to index

bool equalsIgnoreCase ( const char * pszStr ) const 

Tells whether the string is equal to pszStr regardless of char case.

Note:

Uses ::strcasecmp() if available.

Example:

  String s = "Happy";
  if (s.equalsIgnoreCase("HaPPy")) // Success
  ...
  if (s.equals("happy")) // Success
  ...

See also:

bool operator ==( const String & rStr ) const 
bool operator !=( const String & rStr ) const 
bool equals ( const String & rStr ) const 
Back to index

bool equalsIgnoreCase ( const String & rStr ) const 

Overloaded function provided for convenience.

See also:

bool equalsIgnoreCase ( const char * pszStr ) const 
Back to index

bool equals ( const char * pszStr ) const 

Tells whether the string is equal to pszStr. The comparison is case sensitive.

Note:

Uses ::strncmp().

Example:

  String s = "Happy";
  if (s.equals("Happy")) // Success
  ...
  if (s.equals("Yes")) // Failure
  ...

See also:

bool operator ==( const String & rStr ) const 
bool operator !=( const String & rStr ) const 
bool equalsIgnoreCase ( const char * pszStr ) const 
Back to index

bool equals ( const String & rStr ) const 

Overloaded function provided for convenience.

See also:

bool equals ( const char * pszStr ) const 
Back to index

bool operator ==( const char * pszStr ) const 

Overloaded function provided for convenience. Returns the result of the equivalent equal function.

See also:

bool equals ( const char * pszStr ) const 
Back to index

bool operator ==( const String & rStr ) const 

Overloaded function provided for convenience. Returns the result of the equivalent equal function.

See also:

bool equals ( const String & rStr ) const 
Back to index

bool operator ==( char arg ) const 

Overloaded function provided for convenience. Tells whether the string's size is 1 and its char is arg.

See also:

bool operator ==( const String & rStr ) const 
Back to index

bool operator ==( unsigned char arg ) const 

Overloaded function provided for convenience. Tells whether the string's size is 1 and its char is arg.

See also:

bool operator ==( const String & rStr ) const 
Back to index

bool operator ==( int arg ) const 

Overloaded function provided for convenience. Tells whether this string converted to an int is equal to int arg.

See also:

bool operator ==( const String & rStr ) const 
static bool toLong ( const String & rStr , long & rlTarget 
Back to index

bool operator ==( unsigned int arg ) const 

Overloaded function provided for convenience. Tells whether this string converted to an unsigned int is equal to unsigned int arg.

See also:

bool operator ==( const String & rStr ) const 
static bool toUnsignedLong ( const String & rStr , unsigned long & rulTarget 
Back to index

bool operator ==( long arg ) const 

Overloaded function provided for convenience. Tells whether this string converted to a long is equal to long arg.

See also:

bool operator ==( const String & rStr ) const 
static bool toLong ( const String & rStr , long & rlTarget 
Back to index

bool operator ==( unsigned long arg ) const 

Overloaded function provided for convenience. Tells whether this string converted to an unsigned long is equal to unsigned long arg.

See also:

bool operator ==( const String & rStr ) const 
static bool toUnsignedLong ( const String & rStr , unsigned long & rulTarget 
Back to index

bool operator ==float arg ) const 

Overloaded function provided for convenience. Tells whether this string converted to a float is equal to float arg.

See also:

bool operator ==( const String & rStr ) const 
static bool toFloat ( const String & rStr float & rfTarget 
Back to index

bool operator ==double arg ) const 

Overloaded function provided for convenience. Tells whether this string converted to a double is equal to double arg.

See also:

bool operator ==( const String & rStr ) const 
static bool toDouble ( const String & rStr double & rdTarget 
Back to index

bool operator !=( const char * pszStr ) const 

Tells whether pszStr differs from this string. Returns the reverse result of operator==.

See also:

bool operator ==( const char * pszStr ) const 
Back to index

bool operator !=( const String & rStr ) const 

Tells whether rStr differs from this string. Returns the reverse result of operator==.

See also:

bool operator ==( const String & rStr ) const 
Back to index

bool operator !=( unsigned char ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

Back to index

bool operator !=( char ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

bool operator ==( char ) const 
Back to index

bool operator !=( int iSource ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

bool operator ==( int iSource ) const 
Back to index

bool operator !=( unsigned int uiSource ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

bool operator ==( unsigned int uiSource ) const 
Back to index

bool operator !=( long lSource ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

bool operator ==( long lSource ) const 
Back to index

bool operator !=( unsigned long uSource ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

bool operator ==( unsigned long uSource ) const 
Back to index

bool operator !=float fSource ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

bool operator ==float fSource ) const 
Back to index

bool operator !=double dSource ) const 

Overloaded function provided for convenience. Is the opposite function to the one referred to below.

See also:

bool operator ==double dSource ) const 
Back to index

bool startsWith ( const String & rStr ) const 

Tells whether the string starts with string rStr. A constant C string (char*) can also be passed to this method since the String class defines a constructor with such type.

Note:

Uses ::strncmp().

Example:

  String s = "Happy";
  if (s.startsWith("Happ")) // Success
  ...
  if (s.startsWith("Yes")) // Failure
  ...

See also:

bool endsWith ( const String & rStr 
Back to index

bool endsWith ( const String & rStr ) const 

Tells whether the string ends with string rStr. A constant C string (char*) can also be passed to this method since the String class defines a constructor with such type.

Note:

Uses ::strncmp().

Example:

  String s = "Happy";
  if (s.endsWith("py")) // Success
  ...
  if (s.endsWith("Sad")) // Failure
  ...

See also:

bool startsWith ( const String & rStr ) const 
Back to index

bool matchesPattern ( const String & c_sPattern ) const 

Tells whether the string matches the pattern c_sPattern given as a regular expression.

At the moment, the only pattern supported is a single '*' as regular expression.

Example:

  String s = "pattern";
  s.matchesPattern("p*"); // true
  s.matchesPattern("pat*"); // true
  s.matchesPattern("p*n"); // true
  s.matchesPattern("p*sn"); // false

See also:

Back to index

bool matchesPattern ( const StringList & c_slPatternList ) const 

Tells whether the string matches any of the patterns given in the list c_slPatternList.

This function iterates through all patterns of the list by calling the function referred to below.

See also:

bool matchesPattern ( const String & c_sPattern 
Back to index

bool consistsOfChars ( const char * c_pszString ) const 

Tells whether the string is a combination of all the chars part of chararray.

Example:

  String s = "laval";
  const char* pszAllowedChars="alv";
  const char* pszAllowedChars2="alvw";
  if (s.consistsOfChars(pszAllowedChars))
  {
    ... // Success: "laval" consists of 'l', 'a' and 'v' chars.
  }
  if (s.consistsOfChars(pszAllowedChars2))
  {
    ... // Failure: "laval" doesn't contain 'w'.
  }

See also:

Back to index

operator const char * ( ) const 

Cast operator to "const char*". The pointer returned points to the internal char array used to store the string.

Example:

  String s = "won";
  s += "again";
  const char* pszString = (const char*)s; // pszString == "wonagain"

See also:

const char * str ( ) const 
Back to index

bool toString double dSource String & rRes , int iPrecision   [  static  ] 

Converts double dSource to a string. iPrecision is the desired number of decimal numbers. iPrecision is optional and by default iPrecision = 10. If iPrecision < 0, the default precision is the one of %f in ::sprintf().

On success, stores the result in rRes; True is always returned.

Example:

  String s;
  double dVal = -2343545;
  if (String::toString(dVal, s))
  {
    // Success: s == "-2343545"
    ...
  }

Note:

::sprintf(..., "%.iPrecision", dSource) is used for the conversion.

See also:

Back to index

bool toString ( long lSource String & rRes   [  static  ] 

Converts long lSource to a string. On success, stores the result in rRes; True is always returned.

Example:

  String s;
  long iVal = -2343545;
  if (String::toString(iVal, s))
  {
    // Success: s == "-2343545"
    ...
  }

See also:

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

bool toString ( unsigned long uSource String & rRes   [  static  ] 

Converts unsigned long uSource to a string. On success, stores the result in rRes; True is always returned.

Example:

  String s;
  unsigned long uVal = 2343545;
  if (String::toString(uVal, s)
  {
    // Success: s == "2343545"
    ...
  }

See also:

Back to index

bool toLong ( const String & rStr , long & rlTarget   [  static  ] 

Attempts to convert string rStr to an long. On success, i.e. the string contains a valid representation of a long number, stores the result in rlTarget and returns true. On failure, returns false.

Note:

::strtol() is used for the conversion.

Example:

  String s("-2343545");
  long iValue = 0;
  if (String::toLong(s, iValue))
  {
    // Success: iValue == -2343545
    ...
  }

See also:

Back to index

bool toUnsignedLong ( const String & rStr , unsigned long & rulTarget   [  static  ] 

Attempts to convert string rStr to an unsigned long. On success, i.e. the string contains a valid representation of a unsigned long number, stores the result in rulTarget and returns true. On failure, returns false.

Note:

::strtoul() is used for the conversion.

Example:

  String s("2343545");
  unsigned long uVal = 0;
  if (String::toUnsignedLong(s, uValue))
  {
    // Success: uValue == 2343545
    ...
  }

See also:

Back to index

bool toFloat ( const String & rStr float & rfTarget   [  static  ] 

Attempts to convert string rStr to a float. On success, i.e. the string contains a valid representation of a float number, stores the result in rfTarget and returns true. On failure, returns false.

Note:

::strtod() is used for conversion, not ::strtof(). ::strtod() is described by ANSI whereas strtof is described in ISOC99. This function is inaccessible under Linux even with -D_USE_ISOC99

Example:

  String s("121.32");
  float fValue = 0.0;
  if (String::toFloat(s, fValue))
  {
    // Success: fValue == 121.32
    ...
  }

See also:

Back to index

String formatOptionHelp String sOpt String sHelpText , unsigned long uOptColWidth , unsigned long uHelpColWidth , unsigned long uOptNbIndent   [  static  ] 

Formats a standard command line help text for a command option.

The option name given by sOpt is displayed in the first column whose width is given by uOptColWidth. Option names are indented with uOptNbIndent space chars.

uOptColWidth is optional and is equal to 30 by default.

uOptNbIndent is optional and is equal to 2 by default.

The actual help description is displayed in the second column whose width is given by uHelpColWidth.

uHelpColWidth is optional and is equal to 40 by default.

Below given three examples which are excerpt of the UNIX make command line help:

Example:

  -b, -m                      Ignored for compatibility.
  -B, --always-make           Unconditionally make all targets.
  -C DIRECTORY, --directory=DIRECTORY
                              Change to DIRECTORY before doing anything.

See also:

Back to index

bool toDouble ( const String & rStr double & rdTarget   [  static  ] 

Attempts to convert string rStr to a double. On success, i.e. the string contains a valid representation of a double number, stores the result in rdTarget and returns true. On failure, returns false.

Note:

::strtod() is used for conversion.

Example:

  String s("121.32");
  double dValue = 0.0;
  if (String::toDouble(s, dValue))
  {
    // Success: dValue == 121.32
    ...
  }

See also:

Back to index

bool isUINT ( ) const 

Tells whether the string represents an unsigned integer number, regardless of any boundary value consideration. Any leading whitespaces is ignored.

Example:

  String s("232435465657657409");
  s.isUINT(); // Returns true

See also:

static bool toLong ( const String & rStr , long & rlTarget 
Back to index

String toString ( ) const 

Returns a string copy of this one.

See also:

Back to index

String & formatColumn ( unsigned long uColWidth 

Formats the strings so that the text fits into a column of the specified width uColWidth, keeping words unsplitted and adding new lines if necessary.

If a word is longer than the specified width, it is splitted and the '-' split char is shown at the split point.

if uColWidth is zero, the string is emptied.

if uColWidth is 1, there is a char per line and no '-' char showing the split point is shown.

Example:

  String s = "This is a sample text that will be formatted for holding into
  a column of 20 chars.";
  s.formatColumn(20);
  // s ="This is a sample\n
         text that will be\n
         formatted for\n
         holding into a\n
	 column of 20 chars."

Example:

  String s ="awordnotholdinginalinewiththespecifiedwidth"
  s.formatColumn(20);
  // s ="awordnotholdinginal-\n
         inewiththespecified-\n
         width"

See also:

Back to index

String & justify ( unsigned long uColWidth 

Justifies the text so that it occupies the whole column width.

if uColWidth is zero, the string is emptied.

Example:

  String s = "This is a sample
text that will be
formatted for
holding into a
column of 20 chars.";
 s.justify(20);
 // s = "This  is  a   sample
text  that  will  be
formatted        for
holding    into    a
column of 20  chars."

See also:

Back to index

String operator +( const char * c_pszSource , const String &   [  global  ] 

Returns a string resulting from the concatenation of c_pszSource and rStr

See also:

Back to index

bool operator <( const String & s1 , const String & s2   [  global  ] 

"Lesser than" comparison operator between 2 strings.

See also:

Back to index

bool operator >( const String & s1 , const String & s2   [  global  ] 

"Greater than" comparison operator between 2 strings.

See also:

Back to index

std::ostream & operator <<( std::ostream & os , const String &   [  global  ] 

Output stream operator for a string. The content of s is put into the os output stream.

See also:

Back to index


This file is part of the LLOOP LL Object-Oriented Parser Generator and Object Expander Generator. Copyright (c) 2005-2006 Michel MEHL, France. All rights reserved. LLOOP is distributed by the company ERSA SaRL.


Copyright (c) 2005-2006 Michel MEHL, Haguenau, France
LLOOP version 1.1


Generated with makedoc.