The SimpleCxxLib package


#include "strlib.h"

This file exports several useful string functions that are not included in the C++ string library.
Functions
endsWith(str, suffix) Returns true if the string str ends with the specified suffix, which may be either a string or a character.
equalsIgnoreCase(s1, s2) Returns true if s1 and s2 are equal discounting differences in case.
integerToString(n) Converts an integer into the corresponding string of digits.
realToString(d) Converts a floating-point number into the corresponding string form.
startsWith(str, prefix) Returns true if the string str starts with the specified prefix, which may be either a string or a character.
stringToInteger(str) Converts a string of digits into an integer.
stringToReal(str) Converts a string representing a real number into its corresponding value.
toLowerCase(str) Returns a new string in which all uppercase characters have been converted into their lowercase equivalents.
toUpperCase(str) Returns a new string in which all lowercase characters have been converted into their uppercase equivalents.
trim(str) Returns a new string after removing any whitespace characters from the beginning and end of the argument.

Function detail


string integerToString(int n);
Converts an integer into the corresponding string of digits. For example, calling integerToString(123) returns the string "123".

Usage:

string s = integerToString(n);

int stringToInteger(string str);
Converts a string of digits into an integer. If the string is not a legal integer or contains extraneous characters other than whitespace, stringToInteger calls error with an appropriate message.

Usage:

int n = stringToInteger(str);

string realToString(double d);
Converts a floating-point number into the corresponding string form. For example, calling realToString(23.45) returns the string "23.45".

Usage:

string s = realToString(d);

double stringToReal(string str);
Converts a string representing a real number into its corresponding value. If the string is not a legal floating-point number or contains extraneous characters other than whitespace, stringToReal calls error with an appropriate message.

Usage:

double d = stringToReal(str);

string toUpperCase(string str);
Returns a new string in which all lowercase characters have been converted into their uppercase equivalents.

Usage:

string s = toUpperCase(str);

string toLowerCase(string str);
Returns a new string in which all uppercase characters have been converted into their lowercase equivalents.

Usage:

string s = toLowerCase(str);

bool equalsIgnoreCase(string s1, string s2);
Returns 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);
Returns 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);
Returns 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);
Returns a new string after removing any whitespace characters from the beginning and end of the argument.

Usage:

string trimmed = trim(str);