String length |
![]() |
|
|
|
|
|
Returns the string length, in number of characters. CPOS is a typedef declaration that basically translates to int; it is used everywhere in Str Library to represent a character index within a string, or a number of characters.
|
|
|
|
|
Returns TRUE if the string is empty. Equivalent to the expression
GetLength() == 0
Example: copy a Str instance to a dynamically allocated C string
Str s;
// ... load s with data here...
// Compute number of bytes. Add 1 to length because C strings
// must be null-terminated. sizeof(STRCHAR) is always 1 when
// using ANSI encoding, and always 2 for Unicode
int num_bytes = (s.GetLength() + 1) * sizeof(STRCHAR);
// Allocate the memory and copy the characters
STRCHAR* cstring = (STRCHAR*) malloc (num_bytes);
memcpy (cstring, (const STRCHAR*) s, num_bytes);
See also: Basic operations