class CTString
Description
The CTString class represents String objects.
See also
CTChar
Preconditions
This is one of the basic objects from the c-tree database layer.
CTString Operators
- =, +, += : Assignment and concatenation operators
- [ ] : Reference to a character operator
- <, <=, >, >=, ==, != : Comparison operators
CTString::operator =, +, +=
Syntax
CTString& operator=(const CTString& str)
CTString& operator=(const pTEXT str)
CTString& operator+=(const CTString& str)
CTString operator+(const CTString& lhs, const CTString& rhs)
CTString operator+(const pTEXT lhs, const CTString& rhs)Parameters
- str [in] The CTString object or text to be assigned or concatenated to form the new CTString object
- lhs [in] The left hand side string or text to be concatenated
- rhs [in] The right hand side string to be concatenated
Description
Assigns or concatenates a string or text to form a CTString object
Return
The new CTString object
CTString::operator[ ]
Syntax
char& operator[](const NINT index)Parameters
- index [in] The index to search
Description
Returns a reference to the character at the index position.
Return
Returns a reference to the character at the index position, or throws an exception if index<0 or index>length of string.
CTString::operator<, <=, >, >=, ==, !=
Syntax
CTBOOL operator<(const CTString& str)
CTBOOL operator<=(const CTString& str)
CTBOOL operator>(const CTString& str)
CTBOOL operator>=(const CTString& str)
CTBOOL operator==(const CTString& str)
CTBOOL operator!=(const CTString& str)Parameters
- str [in] The string to be compared with the CTString object
Description
Compares the CTString object with str.
Return
Returns YES or NO depending on the result of the comparison.
CTString Methods
Constructor / Destructor
- CTString(): Creates a CTString object
- ~CTString(): Destroys a CTString Object and resets all the dependent objects
String Handling
- c_str(): Returns a ‘C’ language format character string, with the same contents represented by the CTString object
- Compare(): Compares this CTString object to str, with case sensitivity
- CompareIC(): Compares this CTString object to str, with case insensitivity
- Delete(): Deletes characters from the string
- Empty(): Frees the string and sets it to NULL
- Insert(): Inserts substr into this string at position index
- IntToHex(): Converts a number into a string containing the number’s hexadecimal representation
- IsDelimiter(): Verifies if the character at byte index in the CTString matches any character in the delimiters the string str
- IsEmpty(): Verifies if this string is NULL or the length is zero.
- IsPathDelimiter(): Verifies if the character at byte index in the CTString is ‘\’ (or ‘/’ for Unix systems)
- LastChar(): Retrieves a pointer to the last full character in the CTString
- LastDelimiter(): Retrieves the byte index of the rightmost whole character in this CTString
- Left(): Retrieves the count left most characters in the string
- Length(): Retrieves the length of the string
- LowerCase(): Converts this CTString characters to lower case
- PadLeft(): Pads this CTString to the left
- PadRight(): Pads this CTString to the right
- Pos(): Returns the index at which a specified substring begins
- Right(): Retrieves the count right most characters in the string
- SetLength(): Resizes this CTString, truncating or increasing the size of the string
- StringOfChar(): Fills a CTString with the specified number of characters
- SubString(): Retrieves a specified substring of the CTString
- ToInt(): Converts a CTString to an integer
- ToDouble(): Converts a CTString to a double
- Trim(): Removes all spaces from the beginning and from the end of a CTString
- TrimLeft(): Removes all spaces from the beginning of a CTString
- TrimRight(): Removes all spaces from the end of a CTString
- UpperCase(): Converts this CTString characters to upper case
CTString::CTString
Syntax
CTString
CTString(const pTEXT ptr)
CTString(const pTEXT ptr, VRLEN size)
CTString(const CTString& str)
CTString(const NINT value)
CTString(const double value)Parameters
- ptr [in] - pointer to a C String.
- size [in] - size of the string including nul terminator
- str [in] - string to be copied in the copy constructor.
- value [in] - NINT value to be converted to a CTString
Description
This is the constructor for the CTString object. The prototype CTString(const CTString& str) is the copy constructor for the CTString class.
See also
~CTString()
CTString::~CTString
Syntax
~CTStringParameters
This destructor has no parameters.
Description
This is the destructor for the CTString object.
See also
CTString()
CTString::c_str
Syntax
pTEXT c_str( ) constParameters
This method has no parameters.
Description
c_str returns a ‘C’ language format character string, with the same contents represented by the CTString object.
Return
c_str returns a pointer with a null-terminated character array containing the same characters as the CTString class. If the CTString is unassigned, c_str returns NULL.
Example
CTString name = "John";
printf("%s", CTString_sample.c_str());
CTString::Compare
Syntax
NINT Compare(const CTString& str) constParameters
- str [in] The string to be compared.
Description
Compares this CTString object to str, with case sensitivity. This method is NULL safe.
Return
Compare returns:
- A value greater than zero if the CTString object is greater than str
- A value smaller than zero if the CTString object is smaller than str
- Zero if they are the same
See also
CompareIC()
CTString::CompareIC
Syntax
NINT CompareIC(const CTString& str) constParameters
- str [in] The string to be compared.
Description
Compares this CTString object to str, with case insensitivity. This method is NULL safe.
Return
CompareIC() returns:
- A value greater than zero if the CTString object is greater than str
- A value smaller than zero if the CTString object is smaller than str
- Zero if they are the same
See also
Compare()
CTString::Delete
Syntax
void Delete(const NINT index, const NINT count)Parameters
- index [in] The position in the string where characters will be deleted
- count [in] The number of characters to be deleted
Description
Deletes count characters from the string, starting at character position index.
Return
None.
See also
Empty(), Insert()
CTString::Empty
Syntax
void Empty( )Parameters
This method has no parameters.
Description
Frees the string and sets it to NULL.
Return
None.
Example
CTString database_name;
database_name.Empty();
memset(buffer, ' ', sizeof(buffer));
printf("\n\nEnter Database name: ");
gets(buffer);
if (strlen(buffer) > 0)
{
database_name = buffer;
}
See also
Delete(), IsEmpty(), SetLength()
CTString::Insert
Syntax
void Insert(const CTString& substr, const NINT index)Parameters
- substr [in] The substring object to be inserted in the CTString object
- index [in] The position in this string where substr will be inserted.
Description
Inserts substr into this string at position index. The first character position is 0. If index is zero Insert is similar to *this = substr + *this. If index is equal to Length then Insert is similar to *this = *this + substr. If index is less than zero or greater than Length, a CTException is thrown with error code set to CTDBRET_INDEXRANGE (4005). If substr is empty, no operation takes place.
Return
None.
See also
Delete()
CTString::IntToHex
Syntax
CTString IntToHex(const NINT value, const NINT digits)Parameters
- value [in] The integer value to be converted to hexadecimal.
- digits [in] The minimum number of hexadecimal digits. The maximum acceptable value of digits is 256.
Description
Converts a number into a string containing the number’s hexadecimal (base 16) representation.
Return
IntToHex() returns a CTString object with the hexadecimal representation of value.
See also
ToInt()
CTString::IsDelimiter
Syntax
CTBOOL IsDelimiter(const CTString& str, const NINT index) constParameters
- str [in] The string with the delimiter characters.
- index [in] The position in string to check for delimiters. The first position is zero. If index is less than zero or if index is greater or equal to the length of the string, a CTException is thrown with error code CTDBRET_INDEXRANGE (4005).
Description
Verifies if the character at byte index in the CTString matches any character in the delimiters the string str.
Return
IsDelimiter() returns YES if the character at byte index in the CTString matches any character in the delimiters string str, NO otherwise.
See also
IsPathDelimiter()
CTString::IsEmpty
Syntax
CTBOOL IsEmpty( ) constParameters
This method has no parameters.
Description
Verifies if this string is NULL or the length is zero.
Return
IsEmpty() returns YES if the string is NULL or length is zero, NO otherwise.
See also
Empty(), Length()
CTString::IsPathDelimiter
Syntax
CTBOOL IsPathDelimiter(const NINT index)Parameters
- index [in] The position in string to check for path delimiter. The first position is zero. If index is less than zero or if index is greater or equal to the length of the string, a CTException is thrown with error code CTDBRET_INDEXRANGE (4005).
Description
Verifies if the character at byte index in the CTString is ‘\’ (or ‘/’ for Unix systems).
Return
IsPathDelimiter() returns YES if the character at byte index in the CTString is a path delimiter, NO otherwise.
CTString::LastChar
Syntax
pTEXT LastChar( ) constParameters
This method has no parameters.
Description
Retrieves a pointer to the last full character in the CTString.
Return
LastChar() returns a pointer to the last full character in the CTString
See also
LastDelimiter()
CTString::LastDelimiter
Syntax
NINT LastDelimiter(const CTString& delimiters) constParameters
- delimiters [in] string with the delimiters.
Description
Retrieves the byte index in this CTString of the rightmost whole character that matches any character in delimiters, except null (‘\0’).
Return
LastDelimiter() returns the byte index of the rightmost whole character in this CTString.
See also
LastChar(), IsDelimiter()
CTString::Left
Syntax
CTString Left(const NINT count)Parameters
- count [in] The number of characters to be retrieved.
Description
Retrieves the count left most characters in the string. If count is greater than the length of the string, the whole string is returned.
Return
Left returns a CTString object with the count left most characters.
See also
Right()
CTString::Length
Syntax
NINT Length( ) constParameters
This method has no parameters.
Description
Retrieves the length of the string.
Return
Length returns the length of the string. Returns zero if the string is NULL or empty.
See also
IsEmpty(), SetLength()
CTString::LowerCase
Syntax
void LowerCase( )Parameters
This method has no parameters.
Description
Converts this CTString characters to lower case.
Return
None.
See also
UpperCase()
CTString::PadLeft
Syntax
void PadLeft(const NINT newlength, const char padChar= ' ')Parameters
- newlength [in] The length of the padded string. If newlength is less than this CTString, no padding is performed.
- padChar [in] The character used to pad the string. By default, ' ' is used.
Description
Pads this CTString to the left with padChar characters until the length of this CTString is equal to newlength.
Return
None.
See also
PadRight()
CTString::PadRight
Syntax
void PadRight(const NINT newlength, const char padChar= ' ')Parameters
- newlength [in] The length of the padded string. If newlength is less than this CTString, no padding is performed.
- padChar [in] The character used to pad the string. By default, ' ' is used.
Description
Pads this CTString to the right with padChar characters until the length of this CTString is equal to newlength.
Return
None.
CTString::Pos
Syntax
NINT Pos(const CTString& substr) constParameters
- substr [in] The string to look for.
Description
Retrieves the index at which a specified substring begins.
Return
Pos() returns the index number at which a specified substring begins or -1 if substr is not found.
See also
SubString()
CTString::Right
Syntax
CTString Right(const NINT count)Parameters
- count [in] The number of characters to be retrieved.
Description
Retrieves the count right most characters in the string. If count is greater than the length of the string, the whole string is returned.
Return
Right() returns a CTString object with the count right most characters.
See also
Left()
CTString::SetLength
Syntax
void SetLength(const NINT newLength)Parameters
- newLength [in] The new length of the string. If newLength is zero, the string is cleared (set to NULL).
Description
Resizes this CTString. SetLength() truncates or increases the size of the string.
Return
None.
See also
Length(), Empty()
CTString::StringOfChar
Syntax
CTString StringOfChar(const char ch, const NINT count)Parameters
- ch [in] Character used to fill the string.
- count [in] The number of times to repeat the character.
Description
Fills a CTString with the specified number of characters.
Return
StringOfChar() returns the CTString object filled with the specified character.
CTString::SubString
Syntax
CTString SubString(const NINT index, const NINT count) constParameters
- index [in] The start position of the substring. An empty string will be returned if index is greater than the length of the CTString. If index is negative, a CTException is thrown with the error code set to CTDBRET_INDEXRANGE (4005).
- count [in] The maximum number of characters in the substring.
Description
Retrieves a specified substring of the CTString.
Return
SubString returns the CTString object with the substring.
See also
Pos()
CTString::ToInt
Syntax
NINT ToInt( ) constParameters
This method has no parameters.
Description
Converts a CTString to an integer.
Return
ToInt() returns an integer value converted from CTString. ToInt() returns zero if the CTString does not contain a valid integer.
See also
IntToHex(), ToDouble()
CTString::ToDouble
Syntax
double ToDouble( ) constParameters
This method has no parameters.
Description
Converts a CTString to a double.
Return
ToDouble() returns a double value converted from CTString. ToDouble() returns 0.0 if the CTString does not contain a valid floating point number.
See also
ToInt()
CTString::Trim
Syntax
void Trim( )Parameters
This method has no parameters.
Description
Removes all spaces from the beginning and from the end of a CTString.
Return
None.
See also
TrimLeft(), TrimRight()
CTString::TrimLeft
Syntax
void TrimLeft( )Parameters
This method has no parameters.
Description
Removes all spaces from the beginning of a CTString.
Return
None.
See also
Trim(), TrimRight()
CTString::TrimRight
Syntax
void TrimRight( )Parameters
This method has no parameters.
Description
Removes all spaces from the end of a CTString.
Return
None.
See also
Trim(), TrimLeft()
CTString::UpperCase
Syntax
void UpperCase( )Parameters
This method has no parameters.
Description
Converts this CTString characters to upper case.
Return
None.
See also
LowerCase()