Maxima Manual: Verarbeitung von Zeichenketten

Next: Oktette und Werkzeuge für die Kryptographie, Previous: Schriftzeichen, Nach oben: stringproc [Inhalt][Index]

### 73.4 Verarbeitung von Zeichenketten

Positionsindizes in Strings sind in Maxima genau so wie Listen 1-indiziert. Siehe hierzu das Beispiel in charat.

Funktion: charat (string, n)

  Gibt das n-te Schriftzeichen in string zurück. Das erste Zeichen in string erhält man mit n = 1.

  Beispiel:

      (%i1) charat("Lisp",1);
      (%o1)                           L
      (%i2) charlist("Lisp")[1];
      (%o2)                           L

Funktion: charlist (string)

  Gibt eine Liste mit allen Schriftzeichen in string zurück.

  Beispiel:

      (%i1) charlist("Lisp");
      (%o1)                     [L, i, s, p]

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.

  See also parse_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

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.

  See also eval_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)

Funktion: scopy (string)

  Gibt eine Kopie der Zeichenkette string als neue Zeichenkette zurück.

Funktion: sdowncase (string)
Funktion: sdowncase (string, start)
Funktion: sdowncase (string, start, end)

  Arbeitet wie supcase, jedoch werden Groß- in Kleinbuchstaben umgewandelt.

Funktion: sequal (string_1, string_2)

  Gibt `true` zurück, wenn string_1 und string_2 die selbe Zeichensequenz enthalten.

Funktion: sequalignore (string_1, string_2)

  Arbeitet wie sequal, ignoriert jedoch die Groß- und Kleinschreibung, was für Nicht-US-ASCII-Zeichen nur möglich ist, wenn das unter Maxima liegende Lisp einen Buchstaben auch als Buchstaben eines Alphabets erkennen kann. Siehe hierzu die Bemerkungen zu alphacharp.

Funktion: sexplode (string)

  `sexplode` ist ein Alias für die Funktion charlist.

Function: simplode (list)
Function: 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.

  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.

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.

Function: sinvertcase (string)
Function: sinvertcase (string, start)
Function: 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

Funktion: slength (string)

  Gibt die Anzahl der Zeichen in der Zeichenkette string zurück.

Funktion: smake (num, char)

  Gibt eine neue Zeichenkette mit num Zeichen char zurück.

  Beispiel:

      (%i1) smake(3,"w");
      (%o1)                          www

Function: smismatch (string_1, string_2)
Function: 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

Function: split (string)
Function: split (string, delim)
Function: 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]

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.

Function: sremove (seq, string)
Function: sremove (seq, string, test)
Function: sremove (seq, string, test, start)
Function: 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.

Function: sremovefirst (seq, string)
Function: sremovefirst (seq, string, test)
Function: sremovefirst (seq, string, test, start)
Function: sremovefirst (seq, string, test, start, end)

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

Funktion: sreverse (string)

  Gibt eine Zeichenkette mit allen Zeichen von string in umgekehrter Reihenfolge zurück.

Function: ssearch (seq, string)
Function: ssearch (seq, string, test)
Function: ssearch (seq, string, test, start)
Function: 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.

      (%i1) ssearch("~s","~{~S ~}~%",'sequalignore);
      (%o1)                                  4

Function: ssort (string)
Function: 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}`.

      (%i1) ssort("I don't like Mondays.");
      (%o1)                    '.IMaddeiklnnoosty
      (%i2) ssort("I don't like Mondays.",'cgreaterpignore);
      (%o2)                 ytsoonnMlkIiedda.'

Function: ssubst (new, old, string)
Function: ssubst (new, old, string, test)
Function: ssubst (new, old, string, test, start)
Function: 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.

      (%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.

Function: ssubstfirst (new, old, string)
Function: ssubstfirst (new, old, string, test)
Function: ssubstfirst (new, old, string, test, start)
Function: ssubstfirst (new, old, string, test, start, end)

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

Function: strim (seq,string)

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

      (%i1) "/* comment */"$
      (%i2) strim(" /*",%);
      (%o2)                        comment
      (%i3) slength(%);
      (%o3)                           7

Function: striml (seq, string)

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

Function: strimr (seq, string)

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

Funktion: stringp (obj)

  Gibt `true` zurück, wenn obj eine Zeichenkette ist.

  Beispiel: Siehe Einführung.

Function: substring (string, start)
Function: 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.

      (%i1) substring("substring",4);
      (%o1)                        string
      (%i2) substring(%,4,6);
      (%o2)                          in

Function: supcase (string)
Function: supcase (string, start)
Function: 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.

      (%i1) supcase("english",1,2);
      (%o1)                        English

Function: tokens (string)
Function: 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.)

      (%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]

Next: Oktette und Werkzeuge für die Kryptographie, Previous: Schriftzeichen, Nach oben: stringproc [Inhalt][Index]