strlib.h| Functions | |
| Converts a boolean value into the corresponding string form. | |
| Converts a character value into the corresponding string form. | |
Returns true if the string str ends with the specified suffix, which may be either a string or a character. | |
Returns true if s1 and s2 are equal discounting differences in case. | |
| Converts an integer into the corresponding string of digits. | |
| Converts a floating-point number into the corresponding string form. | |
Returns true if the string str starts with the specified prefix, which may be either a string or a character. | |
| Returns whether the given substring can be found in the given string. | |
| Returns the index of the start of the first occurrence of the given substring in the given string. | |
stringIsInteger(str, radix) | Returns whether the given string can be successfully converted into an integer. |
| Returns whether the given string can be successfully converted into a real number. | |
| Concatenates the given vector of strings into a single string using the given separator. | |
| Returns the index of the start of the last occurrence of the given substring in the given string. | |
| Returns a new string with all occurrences of old changed into new. | |
| Breaks apart the given string using the given separator. | |
| Converts a string representing a boolean value into its corresponding value. | |
| Converts a single-character string into its corresponding char value. | |
stringToInteger(str, radix) | Converts a string of digits into an integer. |
| Converts a string representing a real number into its corresponding value. | |
| Returns a new string in which all uppercase characters have been converted into their lowercase equivalents. | |
| Returns a new string in which all lowercase characters have been converted into their uppercase equivalents. | |
| Returns a new string after removing any whitespace characters from the beginning and end of the argument. | |
| Returns a new string after removing any whitespace characters from the end of the argument. | |
| Returns a new string after removing any whitespace characters from the beginning of the argument. | |
| Returns a URL-decoded version of the given string. | |
| Returns a URL-encoded version of the given string. | |
string integerToString(int n);
integerToString(123) returns
the string "123".
Usage:
string s = integerToString(n);
int stringToInteger(string str); int stringToInteger(string str, int radix);
stringToInteger calls error with an
appropriate message.
The function accepts an optional radix (base); for example,
stringToInteger("234", 16) assumes that the string is in base-16 and
returns 2*16*16 + 3*16 + 4 = 564.
Usage:
int n = stringToInteger(str); int n2 = stringToInteger(str, radix);
Second version of this function (with radix parameter) available since: 2015/04/26 version of C++ library
bool stringIsInteger(string str); bool stringIsInteger(string str, int radix);
true if the given string can be successfully converted into an integer; that is, if it consists of digits and an optional +/- sign at the front.
It can be useful to call this function before calling stringToInteger to make sure that the conversion will not fail.
Optionally accepts a radix (base) parameter if base-10 is not desired.
Usage:
if (stringIsInteger(str)) { ...
Available since: 2014/02/01 version of C++ library
Second version of this function (with radix parameter) available since: 2015/04/26 version of C++ library
bool stringIsReal(string str);
true if the given string can be successfully converted into a real number; that is, if it consists of digits, an optional decimal point, an optional +/- sign at the front, and so on.
It can be useful to call this function before calling stringToReal to make sure that the conversion will not fail.
Usage:
if (stringIsReal(str)) { ...
Available since: 2014/02/01 version of C++ library
string realToString(double d);
realToString(23.45) returns
the string "23.45".
Usage:
string s = realToString(d);
double stringToReal(string str);
stringToReal
calls error with an appropriate message.
Usage:
double d = stringToReal(str);
string boolToString(bool b);
boolToString(true) returns
the string "true".
Usage:
string s = boolToString(b);
Available since: 2014/02/01 version of C++ library
bool stringToBool(string str);
"true" or "false".
If the string is not "true" or "false" or contains
extraneous characters other than whitespace, stringToBool
calls error with an appropriate message.
Usage:
bool b = stringToBool(str);
Available since: 2014/02/01 version of C++ library
string charToString(char c);
charToString('Q') returns
the string "Q".
Usage:
string s = charToString(c);
Available since: 2014/02/01 version of C++ library
char stringToChar(string str);
char
value. Typically you can just write str[0] to access the
first character of a string; this function is merely provided for consistency
with the other type-conversion functions.
If the string is not exactly 1 character in length or contains
extraneous characters other than whitespace, stringTochar
calls error with an appropriate message.
Usage:
char c = stringToChar(str);
Available since: 2014/02/01 version of C++ library
bool stringContains(string str, string substr);
true if the given substring can be found within the given string.
Usage:
if (stringContains(str, substr)) { ...
Available since: 2014/02/01 version of C++ library
string stringReplace(string str, string old, string replacement);
str but with all occurrences of old changed into replacement.
Usage:
string s = stringReplace(s, "foo", "bar");
Available since: 2014/02/01 version of C++ library
string toUpperCase(string str);
Usage:
string s = toUpperCase(str);
string toLowerCase(string str);
Usage:
string s = toLowerCase(str);
bool equalsIgnoreCase(string s1, string s2);
true if s1 and s2 are
equal discounting differences in case.
Usage:
if (equalsIgnoreCase(s1, s2)) ...
bool startsWith(string str, string prefix); bool startsWith(string str, char prefix);
true if the string str starts with
the specified prefix, which may be either a string or a character.
Usage:
if (startsWith(str, prefix)) ...
bool endsWith(string str, string suffix); bool endsWith(string str, char suffix);
true if the string str ends with
the specified suffix, which may be either a string or a character.
Usage:
if (endsWith(str, suffix)) ...
string trim(string str);
Usage:
string trimmed = trim(str);
string trimEnd(string str);
Usage:
string trimmed = trimEnd(str);
string trimStart(string str);
Usage:
string trimmed = trimStart(str);
int stringIndexOf(string s, string substring);
s, if it occurs in s.
If it does not occur, returns -1.
This function is very similar to string.find, but find returns string::npos when the string is not found.
Usage:
int index = stringIndexOf(s, sub);
Available since: 2014/02/01 version of C++ library
int stringLastIndexOf(string s, string substring);
s, if it occurs in s.
If it does not occur, returns -1.
This function is very similar to string.rfind, but find returns string::npos when the string is not found.
Usage:
int index = stringLastIndexOf(s, sub);
Available since: 2014/02/01 version of C++ library
vector<string> stringSplit(string str, string delimiter);
"Hi there Jim!" on " " returns {"Hi", "there", "", "Jim!"}.
Usage:
vector<string> v = stringSplit(str, delimiter);
Available since: 2014/02/01 version of C++ library
string stringJoin(const vector<string>& v, string delimiter = "\n");
{"Hi", "there", "", "Jim"} with the delimiter "?" returns "Hi?there??Jim".
Usage:
string s = stringJoin(v, delimiter);
Available since: 2014/02/01 version of C++ library
string urlDecode(string value);
Usage:
string s = urlDecode(value);
Available since: 2014/02/01 version of C++ library
string urlEncode(string value);
Usage:
string s = urlEncode(value);
Available since: 2014/02/01 version of C++ library