bool operator<(const char * pstr) const

A fast comparison of the string object and a character string. This function is mainly used for sorting strings, ie in STL containers. The comparision is case sensitive and numerical rather than lexical. This means that if the function is used for sorting, text strings will not be sorted in lexical order if there is a difference between the character set order and the lexicographic character order of the text.

ParameterDescription
pstrA zero terminated character string to compare with.
Return valueTrue if the string object is less than pstr.

Example:

cstr str("Hello");
bool result = str < "hello";

assert(result);

bool operator>(const char * pstr) const

A fast comparison of the string object and a character string. This function is mainly used for sorting strings. The comparision is case sensitive and numerical rather than lexical. This means that if the function is used for sorting, text strings will not be sorted in lexical order if there is a difference between the character set order and the lexicographic character order of the text.

ParameterDescription
pstrA zero terminated character string to compare with.
Return valueTrue if the string object is greater than pstr.

Example:

cstr str("hello");
bool result = str > "Hello";

assert(result);

bool operator==(const char * pstr) const

A case sensitive comparison of the string object and a character string.

ParameterDescription
pstrA zero terminated character string to compare with.
Return valueTrue if the strings are identical.

Example:

cstr str("Hello");
bool result = str == "Hello";

assert(result);

bool operator!=(const char * pstr) const

A case sensitive comparison of the string object and a character string.

ParameterDescription
pstrA zero terminated character string to compare with.
Return valueFalse if the strings are identical.

Example:

cstr str("hello");
bool result = str != "Hello";

assert(result);

bool sameas(const char * pstr) const

A case insensitive comparison of the string object and a character string. The result depends on the current locale as well as the content of the strings.

ParameterDescription
pstrA zero terminated character string to compare with.
Return valueTrue if the strings are equal.

Example:

cstr str("Hello");
bool result = str.sameas("hello");

assert(result);

int cmp(const char * pstr) const

A fast comparison of the string object and a character string. The comparision is case sensitive and numerical rather than lexical. This means that if the function is used for sorting, text strings will not be sorted in lexical order if there is a difference between the character set order and the lexicographic character order of the text. Use coll() if you need a lexicographic correct comparison.

ParameterDescription
pstrA zero terminated character string to compare with.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("hello");
int result = str.cmp("Hello");

assert(result > 0);

int icmp(const char * pstr) const

A fast comparison of the string object and a character string. The comparision makes no difference between lower and upper case characters. The result depends on the current locale as well as the content of the strings. The comparision is numerical rather than lexical. This means that if the function is used for sorting, text strings will not be sorted in lexical order if there is a difference between the character set order and the lexicographic character order of the text. Use icoll() if you need a lexicographic correct comparison.

ParameterDescription
pstrA zero terminated character string to compare with.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("hello");
int result = str.icmp("Hello");

assert(result == 0);

int ncmp(const char * pstr, size_t len) const

A limited comparison of the string object and a character string. The comparision will stop if a zero termination is found or when len characters have been compared, which ever comes first. The comparision is case sensitive and numerical rather than lexical. This means that if the function is used for sorting, text strings will not be sorted in lexical order if there is a difference between the character set order and the lexicographic character order of the text. Use ncoll() if you need a lexicographic correct comparison.

ParameterDescription
pstrA character string to compare with.
lenMax number of characters to compare.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("Hello World!");
int result = str.ncmp("Hello",5);

assert(result == 0);

int nicmp(const char * pstr, size_t len) const

A limited comparison of the string object and a character string. The comparision will stop if a zero termination is found or when len characters have been compared, which ever comes first. The comparision makes no difference between lower and upper case characters. The result depends on the current locale as well as the content of the strings. The comparision is numerical rather than lexical. This means that if the function is used for sorting, text strings will not be sorted in lexical order if there is a difference between the character set order and the lexicographic character order of the text. Use nicoll() if you need a lexicographic correct comparison.

ParameterDescription
pstrA character string to compare with.
lenMax number of characters to compare.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("Hello World!");
int result = str.nicmp("hello",5);

assert(result == 0);

int coll(const char * pstr) const

Performs a lexicographic comparison of the string object and a character string. The comparision is case sensitive. If the function is used for sorting, the strings will be sorted in the lexicographic order of the current locale.

ParameterDescription
pstrA zero terminated character string to compare with.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("hello");
int result = str.coll("Hello");

assert(result > 0);

int icoll(const char * pstr) const

The function performs a lexicographic comparison of the string object and a character string. The comparision is not case sensitive. If the function is used for sorting, the strings will be sorted in the lexicographic order of the current locale.

This function is not available on all operating systems!

ParameterDescription
pstrA zero terminated character string to compare with.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("hello");
int result = str.icoll("Hello");

assert(result == 0);

int ncoll(const char * pstr, size_t len) const

Performs a lexicographic comparison of the string object and a character string. The comparision is case sensitive. The comparision will stop if a zero termination is found or when len characters have been compared, which ever comes first. If the function is used for sorting, the strings will be sorted in the lexicographic order of the current locale.

This function is not available on all operating systems!

ParameterDescription
pstrA zero terminated character string to compare with.
lenMax number of characters to compare.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("Hello");
int result = str.ncoll("Hello World!",5);

assert(result == 0);

int nicoll(const char * pstr, size_t len) const

The function performs a lexicographic comparison of the string object and a character string. The comparision is not case sensitive. The comparision will stop if a zero termination is found or when len characters have been compared, which ever comes first. If the function is used for sorting, the strings will be sorted in the lexicographic order of the current locale.

This function is not available on all operating systems!

ParameterDescription
pstrA zero terminated character string to compare with.
lenMax number of characters to compare.
Return value<0 if the string object is less than pstr, 0 if the strings are equal, >0 if the string object is greater than pstr.

Example:

cstr str("hello");
int result = str.nicoll("Hello World!",5);

assert(result == 0);

void upr()

Convert all lower case characters in the string object to upper case. The result depends on the current locale as well as the content of the string.

Example:

cstr str("Hello");
str.upr();

assert(str=="HELLO");

void lwr()

Convert all upper case characters in the string object to lower case. The result depends on the current locale as well as the content of the string.

Example:

cstr str("Hello");
str.lwr();

assert(str=="hello");

void cut(size_t len)

Remove a number of characters from the start of the string. The resulting string will be len characters shorter.

ParameterDescription
lenThe number of characters to remove.

Example:

cstr str("ABCDE");
str.cut(3);

assert(str=="DE");

void trunc(size_t len)

Remove a number of characters from the end of the string. The resulting string will be len characters shorter.

ParameterDescription
lenThe number of characters to remove.

Example:

cstr str("ABCDE");
str.trunc(3);

assert(str=="AB");

void trim()

Remove all white space and control characters from the start and the end of the string. White space and control characters that are in the middle of the string will not be removed.

Example:

cstr str(" \tA B C\n");
str.trim();

assert(str=="A B C");

void pad(size_t len, char padding = ' ')

Expand the string object to len characters by padding with the specified character on both sides. The string object will not be modified if it already contains len characters or more.

ParameterDescription
lenThe desired length of the string.
paddingThe character to be used for padding. The default padding character is space.

Example:

cstr str("ABC");
str.pad(7);

assert(str==" ABC ");

void padright(size_t len, char padding = ' ')

Expand the string object to len characters by padding with the specified character at the end of the string. The string object will not be modified if it already contains len characters or more.

ParameterDescription
lenThe desired length of the string.
paddingThe character to be used for padding. The default padding character is space.

Example:

cstr str("ABC");
str.padright(5);

assert(str=="ABC ");

void padleft(size_t len, char padding = ' ')

Expand the string object to len characters by padding with the specified character at the start of the string. The string object will not be modified if it already contains len characters or more.

ParameterDescription
lenThe desired length of the string.
paddingThe character to be used for padding. The default padding character is space.

Example:

cstr str("ABC");
str.padleft(5);

assert(str==" ABC");

void del(size_t from, size_t to)

Delete a sub-string in the string object. The specified bounds are inclusive.

ParameterDescription
fromIndex of the first character to delete.
toIndex of the last character to delete.

Example:

cstr str("ABCabc");
str.del(2,4);

assert(str=="ABc");

void ins(size_t pos, const cstr & str)

Insert the contents of another string object at the specified position.

ParameterDescription
posThe string will be inserted at this position.
strThe string to insert.

Example:

cstr str1("ABCDEF");
cstr str2("abc");
str1.ins(3,str2);

assert(str1=="ABCabcDEF");