Contents > Library Reference > Strings

Strings

Functions for basic string manipulation.

Functions

int strlen(string str) Calculates the number of characters in a string.
string substr(string str, int index, int len) Creates a substring from the source string str. The first character of the string is at zero-based index, with the string being a maximum of len characters. If len is negative, it means -len chars from the end of the string.
string strleft(string str, int len) Creates a substring from the left len characters of the source string str. If len is negative, it means to include all except the last -len chars.
string strright(string str, int len) Creates a substring from the right len characters of the source string str. If len is negative, it means to include all except the first -len chars.
string strupper(string str) Creates a string from the source string str in all uppercase characters.
string strlower(string str) Creates a string from the source string str in all lowercase characters.
int strstr(string str, string sub, int first) Searches the source string str to find sub, beginning at index first.
string strinsert(string str, int pos, string inster) Inserts the string insert into the source string str at index pos, returning the result.
string strreplace(string str, string search, string replace) Replaces all instances of search in the source string str with replace, returning the result.
string hex(int value) Creates a hexadecimal string representation of value in the form "0xh".
string format(float value, int prec) Returns the string representation of value with prec decimal places.
string lformat(float value, int prec) Returns the string representation of value with prec decimal places. The decimal point used is based on the OS locale settings.
float lparse(string value) Converts the string representation value into a float. Unlike relying on the compiler to do the conversion, this function takes into account the decimal point character as defined by the current OS locale settings.
string strctos(char* array) Builds a string from an array of characters, array.
int strstoc(string str, char* array) Copy each character of a str into the character array array.

Contents > Library Reference > Strings > strlen

strlen

int strlen(string str)

Parameters:

str a string

Return value: the length of the string

Calculates the number of characters in a string.


Contents > Library Reference > Strings > substr

substr

string substr(string str, int index, int len)

Parameters:

str a string
index the first character
len the number of characters

Return value: the requested substring

Creates a substring from the source string str. The first character of the string is at zero-based index, with the string being a maximum of len characters. If len is negative, it means -len chars from the end of the string.


Contents > Library Reference > Strings > strleft

strleft

string strleft(string str, int len)

Parameters:

str a string
len the number of characters

Return value: the requested substring

Creates a substring from the left len characters of the source string str. If len is negative, it means to include all except the last -len chars.


Contents > Library Reference > Strings > strright

strright

string strright(string str, int len)

Parameters:

str a string
len the number of characters

Return value: the requested substring

Creates a substring from the right len characters of the source string str. If len is negative, it means to include all except the first -len chars.


Contents > Library Reference > Strings > strupper

strupper

string strupper(string str)

Parameters:

str a string

Return value: the uppercase string

Creates a string from the source string str in all uppercase characters.


Contents > Library Reference > Strings > strlower

strlower

string strlower(string str)

Parameters:

str a string

Return value: the lowercase string

Creates a string from the source string str in all lowercase characters.


Contents > Library Reference > Strings > strstr

strstr

int strstr(string str, string sub, int first)

Parameters:

str the source string
sub the substring to match
first the first index to search

Return value: the location of the match, or -1 if none found

Searches the source string str to find sub, beginning at index first.


Contents > Library Reference > Strings > strinsert

strinsert

string strinsert(string str, int pos, string inster)

Parameters:

str the source string
pos the index at which to insert
inster the string to insert

Return value: the resulting string

Inserts the string insert into the source string str at index pos, returning the result.


Contents > Library Reference > Strings > strreplace

strreplace

string strreplace(string str, string search, string replace)

Parameters:

str the source string
search the string to search for
replace the string to replace with

Return value: the resulting string

Replaces all instances of search in the source string str with replace, returning the result.


Contents > Library Reference > Strings > hex

hex

string hex(int value)

Parameters:

value an integer

Return value: a hexadecimal string representation

Creates a hexadecimal string representation of value in the form "0xh".


Contents > Library Reference > Strings > format

format

string format(float value, int prec)

Parameters:

value float value
prec precision - digits beyond the decimal place

Return value: string representation

Returns the string representation of value with prec decimal places.


Contents > Library Reference > Strings > lformat

lformat

string lformat(float value, int prec)

Parameters:

value float value
prec precision - digits beyond the decimal place

Return value: string representation

Returns the string representation of value with prec decimal places. The decimal point used is based on the OS locale settings.


Contents > Library Reference > Strings > lparse

lparse

float lparse(string value)

Parameters:

value string representation

Return value: float value

Converts the string representation value into a float. Unlike relying on the compiler to do the conversion, this function takes into account the decimal point character as defined by the current OS locale settings.


Contents > Library Reference > Strings > strctos

strctos

string strctos(char* array)

Parameters:

array source array

Return value: string version of array

Builds a string from an array of characters, array.

Note: The final character in the array must be a null character (0).
Contents > Library Reference > Strings > strstoc

strstoc

int strstoc(string str, char* array)

Parameters:

str source string
array destination array

Return value: number of characters copied (include the terminating 0)

Copy each character of a str into the character array array.

Note: The array must be allocated before calling this function. This must either be a local or global array, or an array allocated with new or malloct.