[Top] [Prev] [Next] [Bottom]


[Contents] [Index]

string - string operations

include "string.m";
str:= load String String->PATH;

append:   fn(s: string, l: list of string): list of string;
drop:      fn(s, cl: string)        : string;
in:        fn(c: int, cl: string)   : int;
prefix:    fn(pre, s: string)       : int;
splitl:    fn(s, cl: string)        : (string, string);
splitr:    fn(s, cl: string)        : (string, string);
splitstrl: fn(s,  t: string)        : (string, string);
splitstrr: fn(s,  t: string)        : (string, string);
take:      fn(s, cl: string)        : string;
toint:     fn(s: string, base: int) : (int, string);
tolower:   fn(s: string)            : string;
toupper:   fn(s: string)            : string;

Description

The String module provides general string manipulation functions.

The cl argument to some of these functions is a character class in which a minus sign (-) between any two characters indicates a range and a circumflex (^) in the first position means not in the class. Examples of strings that represent character classes are "a-zA-Z" and "^acg-mr".

append

append: fn(s: string, l: list of string): list of string;
Appends string s to the end of string list l.

drop

drop: fn(s, cl: string): string;
Removes the maximal prefix of string s that is in class cl.

in

in: fn(c: int, cl: string): int;
Returns a 1 if c is in class cl and a 0 if it is not.

prefix

prefix: fn(pre, s: string): int;
Returns a 1 if string pre is a prefix of string s and a 0 if it is not.

splitl

splitl: fn(s, cl: string): (string, string);
Splits string s just before the first character in class cl.

splitr

splitr: fn(s, cl: string): (string, string);
Splits string s just after the last character in class cl.

splitstrl

splitstrl: fn(s, t: string): (string, string);
Splits string s just before the leftmost segment of string s which consists entirely of string t. If string t does not occur in s, the entire string is returned as the first member of the tuple.

Example

splitstrl("aaaxxxbbbxxxooo", "xxx")
returns
("aaa", "xxxbbbxxxooo")


splitstrl (aaaxxxbbbxxxooo, 888) 
returns
(aaaxxxbbbxxxooo, nil)

splitstrr

splitstrr: fn(s, t: string): (string, string);
Splits string s just after the rightmost segment of string s which consists entirely of string t. If string t does not occur in s, the entire string is returned as the second member of the tuple.

Example

splitstrr("aaaxxxbbbxxxooo", "xxx")
returns
("aaaxxxbbbxxx", "ooo")


splitstrr (aaaxxxbbbxxxooo, 888) 
returns
(nil, aaaxxxbbbxxxooo)

take

take: fn(s, cl: string): string;
Returns the maximal prefix of string s that is in class cl.

toint

toint: fn(s: string, base: int): (int, string);
Returns as an integer the value represented by the string s. The string is scanned up to the first character inconsistent with base. The first inconsistent character marks the beginning of the returned string. Leading white-space characters are ignored. The base can be any integer in the range 0 to 36, inclusive.

Example

This code returns the tuple (123, "abcde").

(val, s) := str->toint("123abcde", 10);

tolower

tolower: fn(s: string): string;
Converts all upper case letters in the string s to lower case letters.

toupper

toupper: fn(s: string): string;
Converts all lower case letters in the string s to upper case letters.



[Top] [Prev] [Next] [Bottom]

infernosupport@lucent.com
Copyright © 1997, Lucent Technologies, Inc.. All rights reserved.