unsigned long length_of_string = inline length();
The length()
function returns the length of the string, similar to the
C function strlen()
. Unlike strlen()
, which requires
time to find an answer, length()
requires only time.
bool is_equal = inline equals(const Str& str) const; bool is_equal = equals(const char* cstr) const;
The equals()
function is similar to the strcmp()
function
except that equals()
returns only true
or false
. The
equals(const Str& str)
form of the function will operate in
time if the strings are different lengths or a string is
compared with itself. In other cases, the function has
efficiency.
bool starts_with = inline startsWith(const Str& str) const; bool starts_with = startsWith(const char* cstr) const; bool ends_with = inline endsWith(const char* cstr) const; bool ends_with = inline endsWith(const Str& str) const;
These functions return true if the given substring is at the beginning or the end of the string. For example:
Str x = "Hello"; x.startsWith("He"); // true x.endsWith("o"); // true x.startsWith("Hello"); // true x.endsWith("Hello"); // true x.startsWith("he"); // false x.endsWith("tion"); // false
The startsWith()
function will operate with efficiency if
a Str
is passed to it and the substring is longer than the string
compared against. In all other cases, these functions have
efficiency.