To contents
Next section
11.1 String
The module String contains some extra string functionality which
is not always used. These functions are mostly implemented in Pike as a
complement to those written in C.
- FUNCTION
- String.fuzzymatch - make a fuzzy compare of two strings
- SYNTAX
-
int fuzzymatch(string word1, string word2);
- DESCRIPTION
-
This function compares two strings using a fuzzy matching
routine. The higher the resulting value, the better the strings match.
- EXAMPLE
-
> fuzzymatch("cat", "hat");
Result: 66
> fuzzymatch("cat", "dog");
Result: 0
> fuzzymatch("United States", "United Nations");
Result: 70
- SEE ALSO
- Array.diff, Array.diff_compare_table and Array.diff_longest_sequence
- FUNCTION
- String.implode_nicely - make an English comma separated list
- SYNTAX
-
string implode_nicely(array(string|float|int) words, string|void separator);
- DESCRIPTION
-
This function implodes a list of words to a readable string.
If the separator is omitted, the default is "and".
If the words are numbers they are converet to strings first.
- EXAMPLE
-
> implode_nicely(({"green"}));
Result: green
> implode_nicely(({"green","blue"}));
Result: green and blue
> implode_nicely(({"green","blue","white"}));
Result: green, blue and white
> implode_nicely(({"green","blue","white"}),"or");
Result: green, blue or white
> implode_nicely(({1,2,3}),"or even");
Result: 1, 2 or even 3
- SEE ALSO
- `*
- FUNCTION
- String.capitalize - capitalize a string
- SYNTAX
-
string capitalize(string str);
- DESCRIPTION
-
Convert the first character in str to upper case, and return the
new string.
- SEE ALSO
- lower_case and upper_case
- FUNCTION
- String.common_prefix - find the longest common beginning
- SYNTAX
-
string common_prefix(array(string) strs);
- DESCRIPTION
-
Find the longest common beginning from an array of strings.
- EXAMPLE
-
> String.common_prefix(({ "muzzle", "muzzy" }));
Result: "muzz"
> String.common_prefix(({ "labyrinth", "diatom" }));
Result: ""
> String.common_prefix(({}));
Result: ""
- FUNCTION
- String.sillycaps - Sillycaps A String
- SYNTAX
-
string sillycaps(string str);
- DESCRIPTION
-
Convert the first character in each word (separated by spaces) in str to upper case, and return the new string.
- FUNCTION
- String.strmult - multiply strings
- SYNTAX
-
string strmult(string s, int num);
- DESCRIPTION
-
This function multiplies 's' by 'num'. The return value is the same
as appending 's' to an empty string 'num' times.
- FUNCTION
- String.count - count needles in a haystack string
- SYNTAX
-
string count(string haystack, string needle);
- DESCRIPTION
-
This function counts the number of times the needle
can be found in haystack.
Intersections between needles are not counted, ie
count("....","..") is 2.
- FUNCTION
- String.width - return width of string
- SYNTAX
-
int width(string s);
- DESCRIPTION
-
Returns the width in bits (8, 16 or 32) of the widest character in s.
- FUNCTION
- String.trim_whites - trim spaces and tabs from a string
- SYNTAX
-
string trim_whites(string s);
- DESCRIPTION
-
Trim leading and trailing spaces and tabs from the string s.
- FUNCTION
- String.trim_all_whites - trim all white spaces from a string
- SYNTAX
-
string trim_all_whites(string s);
- DESCRIPTION
-
Trim leading and trailing white space characters (" \t\r\n") from the string s.
To contents
Next section