Next: , Previous: , Up: stringproc   [Contents][Index]

91.4 String Processing

Position indices in strings are 1-indexed like in Maxima lists. See example in charat.

Function: charat (string, n)

Returns the n-th character of string. The first character in string is returned with n = 1.

(%i1) charat("Lisp",1);
(%o1)                           L
(%i2) charlist("Lisp")[1];
(%o2)                           L
Categories: Package stringproc ·
Function: charlist (string)

Returns the list of all characters in string.

(%i1) charlist("Lisp");
(%o1)                     [L, i, s, p]
Categories: Package stringproc ·
Function: eval_string (str)

Parse the string str as a Maxima expression and evaluate it. The string str may or may not have a terminator (dollar sign $ or semicolon ;). Only the first expression is parsed and evaluated, if there is more than one.

Complain if str is not a string.

Examples:

(%i1) eval_string ("foo: 42; bar: foo^2 + baz");
(%o1)                       42
(%i2) eval_string ("(foo: 42, bar: foo^2 + baz)");
(%o2)                   baz + 1764

See also parse_string and eval_string_lisp.

Categories: Package stringproc ·
Function: parse_string (str)

Parse the string str as a Maxima expression (do not evaluate it). The string str may or may not have a terminator (dollar sign $ or semicolon ;). Only the first expression is parsed, if there is more than one.

Complain if str is not a string.

Examples:

(%i1) parse_string ("foo: 42; bar: foo^2 + baz");
(%o1)                    foo : 42
(%i2) parse_string ("(foo: 42, bar: foo^2 + baz)");
                                   2
(%o2)          (foo : 42, bar : foo  + baz)

See also eval_string.

Categories: Package stringproc ·
Function: scopy (string)

Returns a copy of string as a new string.

Categories: Package stringproc ·
Function: sdowncase
    sdowncase (string)
    sdowncase (string, start)
    sdowncase (string, start, end)

Like supcase but uppercase characters are converted to lowercase.

Categories: Package stringproc ·
Function: sequal (string_1, string_2)

Returns true if string_1 and string_2 contain the same sequence of characters.

Function: sequalignore (string_1, string_2)

Like sequal but ignores case which is only possible for non-US-ASCII characters when the underlying Lisp is able to recognize a character as an alphabetic character. See remarks on alphacharp.

Function: sexplode (string)

sexplode is an alias for function charlist.

Categories: Package stringproc ·
Function: simplode
    simplode (list)
    simplode (list, delim)

simplode takes a list of expressions and concatenates them into a string. If no delimiter delim is specified, simplode uses no delimiter. delim can be any string.

See also concat, sconcat, string and printf.

Examples:

(%i1) simplode(["xx[",3,"]:",expand((x+y)^3)]);
(%o1)             xx[3]:y^3+3*x*y^2+3*x^2*y+x^3
(%i2) simplode( sexplode("stars")," * " );
(%o2)                   s * t * a * r * s
(%i3) simplode( ["One","more","coffee."]," " );
(%o3)                   One more coffee.
Categories: Package stringproc ·
Function: sinsert (seq, string, pos)

Returns a string that is a concatenation of substring(string, 1, pos-1), the string seq and substring (string, pos). Note that the first character in string is in position 1.

Examples:

(%i1) s: "A submarine."$
(%i2) concat( substring(s,1,3),"yellow ",substring(s,3) );
(%o2)                  A yellow submarine.
(%i3) sinsert("hollow ",s,3);
(%o3)                  A hollow submarine.
Categories: Package stringproc ·
Function: sinvertcase
    sinvertcase (string)
    sinvertcase (string, start)
    sinvertcase (string, start, end)

Returns string except that each character from position start to end is inverted. If end is not given, all characters from start to the end of string are replaced.

Examples:

(%i1) sinvertcase("sInvertCase");
(%o1)                      SiNVERTcASE
Categories: Package stringproc ·
Function: slength (string)

Returns the number of characters in string.

Categories: Package stringproc ·
Function: smake (num, char)

Returns a new string with a number of num characters char.

Example:

(%i1) smake(3,"w");
(%o1)                          www
Categories: Package stringproc ·
Function: smismatch
    smismatch (string_1, string_2)
    smismatch (string_1, string_2, test)

Returns the position of the first character of string_1 at which string_1 and string_2 differ or false. Default test function for matching is sequal. If smismatch should ignore case, use sequalignore as test.

Example:

(%i1) smismatch("seven","seventh");
(%o1)                           6
Categories: Package stringproc ·
Function: split
    split (string)
    split (string, delim)
    split (string, delim, multiple)

Returns the list of all tokens in string. Each token is an unparsed string. split uses delim as delimiter. If delim is not given, the space character is the default delimiter. multiple is a boolean variable with true by default. Multiple delimiters are read as one. This is useful if tabs are saved as multiple space characters. If multiple is set to false, each delimiter is noted.

Examples:

(%i1) split("1.2   2.3   3.4   4.5");
(%o1)                 [1.2, 2.3, 3.4, 4.5]
(%i2) split("first;;third;fourth",";",false);
(%o2)               [first, , third, fourth]
Categories: Package stringproc ·
Function: sposition (char, string)

Returns the position of the first character in string which matches char. The first character in string is in position 1. For matching characters ignoring case see ssearch.

Categories: Package stringproc ·
Function: sremove
    sremove (seq, string)
    sremove (seq, string, test)
    sremove (seq, string, test, start)
    sremove (seq, string, test, start, end)

Returns a string like string but without all substrings matching seq. Default test function for matching is sequal. If sremove should ignore case while searching for seq, use sequalignore as test. Use start and end to limit searching. Note that the first character in string is in position 1.

Examples:

(%i1) sremove("n't","I don't like coffee.");
(%o1)                   I do like coffee.
(%i2) sremove ("DO ",%,'sequalignore);
(%o2)                    I like coffee.
Categories: Package stringproc ·
Function: sremovefirst
    sremovefirst (seq, string)
    sremovefirst (seq, string, test)
    sremovefirst (seq, string, test, start)
    sremovefirst (seq, string, test, start, end)

Like sremove except that only the first substring that matches seq is removed.

Categories: Package stringproc ·
Function: sreverse (string)

Returns a string with all the characters of string in reverse order.

See also reverse.

Categories: Package stringproc ·
Function: ssearch
    ssearch (seq, string)
    ssearch (seq, string, test)
    ssearch (seq, string, test, start)
    ssearch (seq, string, test, start, end)

Returns the position of the first substring of string that matches the string seq. Default test function for matching is sequal. If ssearch should ignore case, use sequalignore as test. Use start and end to limit searching. Note that the first character in string is in position 1.

Example:

(%i1) ssearch("~s","~{~S ~}~%",'sequalignore);
(%o1)                                  4
Categories: Package stringproc ·
Function: ssort
    ssort (string)
    ssort (string, test)

Returns a string that contains all characters from string in an order such there are no two successive characters c and d such that test (c, d) is false and test (d, c) is true. Default test function for sorting is clessp. The set of test functions is {clessp, clesspignore, cgreaterp, cgreaterpignore, cequal, cequalignore}.

Examples:

(%i1) ssort("I don't like Mondays.");
(%o1)                    '.IMaddeiklnnoosty
(%i2) ssort("I don't like Mondays.",'cgreaterpignore);
(%o2)                 ytsoonnMlkIiedda.'   
Categories: Package stringproc ·
Function: ssubst
    ssubst (new, old, string)
    ssubst (new, old, string, test)
    ssubst (new, old, string, test, start)
    ssubst (new, old, string, test, start, end)

Returns a string like string except that all substrings matching old are replaced by new. old and new need not to be of the same length. Default test function for matching is sequal. If ssubst should ignore case while searching for old, use sequalignore as test. Use start and end to limit searching. Note that the first character in string is in position 1.

Examples:

(%i1) ssubst("like","hate","I hate Thai food. I hate green tea.");
(%o1)          I like Thai food. I like green tea.
(%i2) ssubst("Indian","thai",%,'sequalignore,8,12);
(%o2)         I like Indian food. I like green tea.
Categories: Package stringproc ·
Function: ssubstfirst
    ssubstfirst (new, old, string)
    ssubstfirst (new, old, string, test)
    ssubstfirst (new, old, string, test, start)
    ssubstfirst (new, old, string, test, start, end)

Like subst except that only the first substring that matches old is replaced.

Categories: Package stringproc ·
Function: strim (seq,string)

Returns a string like string, but with all characters that appear in seq removed from both ends.

Examples:

(%i1) "/* comment */"$
(%i2) strim(" /*",%);
(%o2)                        comment
(%i3) slength(%);
(%o3)                           7
Categories: Package stringproc ·
Function: striml (seq, string)

Like strim except that only the left end of string is trimmed.

Categories: Package stringproc ·
Function: strimr (seq, string)

Like strim except that only the right end of string is trimmed.

Categories: Package stringproc ·
Function: stringp (obj)

Returns true if obj is a string. See introduction for example.

Function: substring
    substring (string, start)
    substring (string, start, end)

Returns the substring of string beginning at position start and ending at position end. The character at position end is not included. If end is not given, the substring contains the rest of the string. Note that the first character in string is in position 1.

Examples:

(%i1) substring("substring",4);
(%o1)                        string
(%i2) substring(%,4,6);
(%o2)                          in
Categories: Package stringproc ·
Function: supcase
    supcase (string)
    supcase (string, start)
    supcase (string, start, end)

Returns string except that lowercase characters from position start to end are replaced by the corresponding uppercase ones. If end is not given, all lowercase characters from start to the end of string are replaced.

Example:

(%i1) supcase("english",1,2);
(%o1)                        English
Categories: Package stringproc ·
Function: tokens
    tokens (string)
    tokens (string, test)

Returns a list of tokens, which have been extracted from string. The tokens are substrings whose characters satisfy a certain test function. If test is not given, constituent is used as the default test. {constituent, alphacharp, digitcharp, lowercasep, uppercasep, charp, characterp, alphanumericp} is the set of test functions. (The Lisp-version of tokens is written by Paul Graham. ANSI Common Lisp, 1996, page 67.)

Examples:

(%i1) tokens("24 October 2005");
(%o1)                  [24, October, 2005]
(%i2) tokens("05-10-24",'digitcharp);
(%o2)                     [05, 10, 24]
(%i3) map(parse_string,%);
(%o3)                      [5, 10, 24]
Categories: Package stringproc ·

Next: , Previous: , Up: stringproc   [Contents][Index]