Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Libraries AES ARC4 Array ASN.1 Bigfile Bigint Bigrat Bin32 Bin64 Bitdata Bitmapfont Bitset Bitsetof Boolean Browser Bstring Bytedata Cards Category CC config Cgi Cgi dialog Char Charsets Cipher Clib_file Color CLI Commands Complex Console Crc32 Deflate DES Dialog Dir Draw Duration Echo Editline Enable_input Enable_io Enable_output Encoding Environment External_file File File system Float Font Forloop Ftp Getf Gethttp Gethttps Graph Graph_file Gzip Hash Hashsetof Hmac Html_ent Httpserv Idxarray Image Inflate Inflate file Inifile Integer Keybd Line Listener LZW Make Math Msgdigest Null_file Osfiles Picture utility Pixmap_file Pixmapfont PKCS #1 Poll Process Progs Propertyfile Rational Reference Ref_list Scanfile Scanstri Set Shell Smtp Sockbase Socket SQL base Stdio Strifile String Stritext Subrange Tar Text Time TLS/SSL Triple DES Unicode Utf16 Utf8 Vectorfont 3D Vector Wildcard Window Wrinum X.509 Xmldom Xml_ent Zip
Libraries
String Source Code
 previous   up   next 

Operator Summary
string
(in string: stri) mult (in integer: factor)
String multiplication.
string
(in string: stri) lpad (in integer: length)
Pad a string with spaces at the left side up to a given length.
string
(in string: stri) lpad0 (in integer: length)
Pad a string with zeroes at the left side up to a given length.
string
(in string: stri) rpad (in integer: length)
Pad a string with spaces at the right side up to a given length.
string
(in string: stri1) & (in string: stri2)
Concatenate two strings.
string
(in string: stri1) <& (in string: stri2)
Concatenate two strings.
char
(in string: stri) [ (in integer: index) ]
Get a character, identified by an index, from a string.
string
(in string: stri) [ (in integer: start) .. ]
Get a substring beginning at a start position.
string
(in string: stri) [ .. (in integer: stop) ]
Get a substring ending at a stop position.
string
(in string: stri) [ (in integer: start) .. (in integer: stop) ]
Get a substring from a start position to a stop position.
string
(in string: stri) [ (in integer: start) len (in integer: length) ]
Get a substring from a start position with a given length.
void
(inout string: destination) &:= (in string: extension)
Append the string extension to destination.
void
(inout string: destination) &:= (in char: extension)
Append the char extension to destination.
void
(inout string: destination) @:= [ (in integer: position) ] (in char: source)
Assign char source to the position of the destination.
void
(inout string: destination) @:= [ (in integer: position) ] (in string: source)
Assign string source to the position of the destination.
boolean
(in string: stri1) = (in string: stri2)
Check if two strings are equal.
boolean
(in string: stri1) <> (in string: stri2)
Check if two strings are not equal.
boolean
(in string: stri1) < (in string: stri2)
Check if stri1 is less than stri2.
boolean
(in string: stri1) > (in string: stri2)
Check if stri1 is greater than stri2.
boolean
(in string: stri1) <= (in string: stri2)
Check if stri1 is less than or equal to stri2.
boolean
(in string: stri1) >= (in string: stri2)
Check if stri1 is greater than or equal to stri2.
string
(attr string) parse (in string: stri)
Convert to a string.

Function Summary
integer
compare (in string: stri1, in string: stri2)
Compare two strings.
integer
hashCode (in string: stri)
Compute the hash value of a string.
integer
length (in string: stri)
Determine the length of a string.
boolean
startsWith (in string: stri, in string: prefix)
Determine if a string starts with a prefix.
boolean
endsWith (in string: stri, in string: suffix)
Determine if a string ends with a suffix.
boolean
equalAtIndex (in string: stri, in string: searched, in integer: index)
Check if stri has the searched characters starting from index.
integer
pos (in string: mainStri, in string: searched)
Determine leftmost position of string searched in mainStri.
integer
pos (in string: mainStri, in char: searched)
Determine leftmost position of char searched in mainStri.
integer
pos (in string: mainStri, in string: searched, in integer: fromIndex)
Search string searched in mainStri at or after fromIndex.
integer
pos (in string: mainStri, in char: searched, in integer: fromIndex)
Search char searched in mainStri at or after fromIndex.
integer
rpos (in string: mainStri, in string: searched)
Determine rightmost position of string searched in mainStri.
integer
rpos (in string: mainStri, in char: searched)
Determine rightmost position of char searched in mainStri.
integer
rpos (in string: mainStri, in string: searched, in integer: fromIndex)
Search string searched in mainStri at or before fromIndex.
integer
rpos (in string: mainStri, in char: searched, in integer: fromIndex)
Search char searched in mainStri at or before fromIndex.
string
replace (in string: mainStri, in string: target, in string: replacement)
Replace occurrences of target in mainStri by replacement.
string
replaceN (in string: mainStri, in string: target, in string: replacement)
Replace all occurrences of target in mainStri by replacement.
string
replace2 (in string: mainStri, in string: search1, in string: search2, in string: replacement)
Replace occurrences of search1 followed by search2 with replacement.
string
upper (in string: stri)
Convert a string to upper case.
string
lower (in string: stri)
Convert a string to lower case.
string
trim (in string: stri)
Return string with leading and trailing whitespace omitted.
string
ltrim (in string: stri)
Return string with leading whitespace omitted.
string
rtrim (in string: stri)
Return string with trailing whitespace omitted.
string
trimValue (in type: aType, in string: stri)
Trim a string such that it can be converted to aType.
string
trimValue (attr string, in string: stri)
Trim a string such that it can be converted to string.
string
str (in string: stri)
Convert to a string.

Operator Detail

mult

const func string: (in string: stri) mult (in integer: factor)

String multiplication. The string stri is concatenated to itself such that in total factor strings are concatenated.

"LA" mult 3     returns "LALALA"
"WORD" mult 0   returns ""
Returns:
the result of the string multiplication.
Raises:
RANGE_ERROR - When the factor is negative.

lpad

const func string: (in string: stri) lpad (in integer: length)

Pad a string with spaces at the left side up to a given length.

Returns:
the string left padded with spaces.

lpad0

const func string: (in string: stri) lpad0 (in integer: length)

Pad a string with zeroes at the left side up to a given length.

Returns:
the string left padded with zeroes.

rpad

const func string: (in string: stri) rpad (in integer: length)

Pad a string with spaces at the right side up to a given length.

Returns:
the string right padded with spaces.

&

const func string: (in string: stri1) & (in string: stri2)

Concatenate two strings. This operator is intended for normal expressions. Its parameters are not converted to string.

Returns:
the result of the concatenation.

<&

const func string: (in string: stri1) <& (in string: stri2)

Concatenate two strings. This operator is intended for write statements. The functions enable_io respectively enable_output overload the <& operator for many types. This overloaded operators optionally convert parameters to string.

Returns:
the result of the concatenation.

[

const func char: (in string: stri) [ (in integer: index) ]

Get a character, identified by an index, from a string. The first character has the index 1.

Returns:
the character specified with the index.
Raises:
RANGE_ERROR - When the index is less than 1 or greater than the length of the string.

[

const func string: (in string: stri) [ (in integer: start) .. ]

Get a substring beginning at a start position. The first character in a string has the position 1.

Returns:
the substring beginning at the start position.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

[ ..

const func string: (in string: stri) [ .. (in integer: stop) ]

Get a substring ending at a stop position. The first character in a string has the position 1.

Returns:
the substring ending at the stop position.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

[

const func string: (in string: stri) [ (in integer: start) .. (in integer: stop) ]

Get a substring from a start position to a stop position. The first character in a string has the position 1.

Returns:
the substring from position start to stop.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

[

const func string: (in string: stri) [ (in integer: start) len (in integer: length) ]

Get a substring from a start position with a given length. The first character in a string has the position 1.

Returns:
the substring from the start position with a given length.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

&:=

const proc: (inout string: destination) &:= (in string: extension)

Append the string extension to destination.

Raises:
MEMORY_ERROR - Not enough memory for the concatenated string.

&:=

const proc: (inout string: destination) &:= (in char: extension)

Append the char extension to destination.

Raises:
MEMORY_ERROR - Not enough memory for the concatenated string.

@:= [

const proc: (inout string: destination) @:= [ (in integer: position) ] (in char: source)

Assign char source to the position of the destination.

A @:= [B] C;

is equivalent to

A := A[..pred(B)] & str(C) & A[succ(B)..];
Raises:
RANGE_ERROR - When position is negative or zero.
RANGE_ERROR - A character beyond destination would be overwritten (position > length(destination) holds).

@:= [

const proc: (inout string: destination) @:= [ (in integer: position) ] (in string: source)

Assign string source to the position of the destination.

A @:= [B] C;

is equivalent to

A := A[..pred(B)] & C & A[B+length(C)..];
Raises:
RANGE_ERROR - When position is negative or zero.
RANGE_ERROR - When destination is smaller than source.
RANGE_ERROR - Characters beyond destination would be overwritten (position + length(source) > succ(length(destination)) holds).

=

const func boolean: (in string: stri1) = (in string: stri2)

Check if two strings are equal.

Returns:
TRUE if both strings are equal, FALSE otherwise.

<>

const func boolean: (in string: stri1) <> (in string: stri2)

Check if two strings are not equal.

Returns:
FALSE if both strings are equal, TRUE otherwise.

<

const func boolean: (in string: stri1) < (in string: stri2)

Check if stri1 is less than stri2.

Returns:
TRUE if stri1 is less than stri2, FALSE otherwise.

>

const func boolean: (in string: stri1) > (in string: stri2)

Check if stri1 is greater than stri2.

Returns:
TRUE if stri1 is greater than stri2, FALSE otherwise.

<=

const func boolean: (in string: stri1) <= (in string: stri2)

Check if stri1 is less than or equal to stri2.

Returns:
TRUE if stri1 is less than or equal to stri2, FALSE otherwise.

>=

const func boolean: (in string: stri1) >= (in string: stri2)

Check if stri1 is greater than or equal to stri2.

Returns:
TRUE if stri1 is greater than or equal to stri2, FALSE otherwise.

parse

const func string: (attr string) parse (in string: stri)

Convert to a string.

Returns:
its parameter unchanged.

Function Detail

compare

const func integer: compare (in string: stri1, in string: stri2)

Compare two strings.

Returns:
-1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.

hashCode

const func integer: hashCode (in string: stri)

Compute the hash value of a string.

Returns:
the hash value.

length

const func integer: length (in string: stri)

Determine the length of a string.

Returns:
the length of the string.

startsWith

const func boolean: startsWith (in string: stri, in string: prefix)

Determine if a string starts with a prefix.

startsWith("tmp_s7c.c", "tmp_")  returns TRUE
startsWith("example", "E")       returns FALSE
Returns:
TRUE if stri starts with prefix, FALSE otherwise.

endsWith

const func boolean: endsWith (in string: stri, in string: suffix)

Determine if a string ends with a suffix.

endsWith("hello.sd7", ".sd7")  returns TRUE
endsWith("A string", "\0;")    returns FALSE
Returns:
TRUE if stri ends with suffix, FALSE otherwise.

equalAtIndex

const func boolean: equalAtIndex (in string: stri, in string: searched, in integer: index)

Check if stri has the searched characters starting from index.

equalAtIndex("The quick brown fox", "quick", 5)  returns TRUE
equalAtIndex("axis", "xi", 3)                    returns FALSE
Returns:
TRUE if stri has the searched characters starting from index, FALSE otherwise.

pos

const func integer: pos (in string: mainStri, in string: searched)

Determine leftmost position of string searched in mainStri. When the string is found the position of its first character is the result. The first character in a string has the position 1.

Returns:
the position of searched or 0 when mainStri does not contain searched.

pos

const func integer: pos (in string: mainStri, in char: searched)

Determine leftmost position of char searched in mainStri. The first character in a string has the position 1.

Returns:
the position of searched or 0 when mainStri does not contain searched.

pos

const func integer: pos (in string: mainStri, in string: searched, in integer: fromIndex)

Search string searched in mainStri at or after fromIndex. The search starts at fromIndex and proceeds to the right. When the string is found the position of its first character is the result. The first character in a string has the position 1. The pos function is designed to allow loops like:

index := pos(stri, searched_stri);
while index <> 0 do
  # Do something with index
  index := pos(stri, searched_stri, succ(index));
end while;
Returns:
the position of searched or 0 when mainStri does not contain searched at or after fromIndex.
Raises:
RANGE_ERROR - When fromIndex <= 0 holds.

pos

const func integer: pos (in string: mainStri, in char: searched, in integer: fromIndex)

Search char searched in mainStri at or after fromIndex. The search starts at fromIndex and proceeds to the right. The first character in a string has the position 1.

Returns:
the position of searched or 0 when mainStri does not contain searched at or after fromIndex.
Raises:
RANGE_ERROR - When fromIndex <= 0 holds.

rpos

const func integer: rpos (in string: mainStri, in string: searched)

Determine rightmost position of string searched in mainStri. When the string is found the position of its first character is the result. The first character in a string has the position 1.

Returns:
the position of searched or 0 when mainStri does not contain searched.

rpos

const func integer: rpos (in string: mainStri, in char: searched)

Determine rightmost position of char searched in mainStri. The first character in a string has the position 1.

Returns:
the position of searched or 0 when mainStri does not contain searched.

rpos

const func integer: rpos (in string: mainStri, in string: searched, in integer: fromIndex)

Search string searched in mainStri at or before fromIndex. The search starts at fromIndex and proceeds to the left. The first character in a string has the position 1. The rpos function is designed to allow loops like:

index := rpos(stri, searched_stri);
while index <> 0 do
  # Do something with index
  index := rpos(stri, searched_stri, pred(index));
end while;
Returns:
the position of searched or 0 when mainStri does not contain searched at or before fromIndex.
Raises:
RANGE_ERROR - When fromIndex > length(stri) holds.

rpos

const func integer: rpos (in string: mainStri, in char: searched, in integer: fromIndex)

Search char searched in mainStri at or before fromIndex. The search starts at fromIndex and proceeds to the left. The first character in a string has the position 1.

Returns:
the position of searched or 0 when mainStri does not contain searched at or before fromIndex.
Raises:
RANGE_ERROR - When fromIndex > length(stri) holds.

replace

const func string: replace (in string: mainStri, in string: target, in string: replacement)

Replace occurrences of target in mainStri by replacement. The function processes mainStri from left to right and replaces target by replacement. After a target has been replaced the search for the next target starts after the replacement. If a replacement creates new occurances of target they are left intact.

replace("old gold", "old", "one")        returns "one gone"
replace("it   is very  low", "  ", " ")  returns "it  is very low"
replace("balll", "all", "al")            returns "ball"
replace("faaaaceeees", "aacee", "ace")   returns "faaaceees"
Returns:
the result of the replacement.

replaceN

const func string: replaceN (in string: mainStri, in string: target, in string: replacement)

Replace all occurrences of target in mainStri by replacement. The function processes mainStri from left to right and replaces target by replacement. If a replacement creates new occurances of target they are replaced also. This can be used to replace multiple occurances of a character by one occurance

replace("//path///file", "//", "/")      returns "/path/file"
replace("it   is very  low", "  ", " ")  returns "it is very low"
replace("balll", "all", "al")            returns "bal"
replace("faaaaceeees", "aacee", "ace")   returns "faces"
Returns:
the result of the replacement.
Raises:
MEMORY_ERROR - When target is a substring of replacement.

replace2

const func string: replace2 (in string: mainStri, in string: search1, in string: search2, in string: replacement)

Replace occurrences of search1 followed by search2 with replacement. Searches mainStri for search1 followed by search2. The characters from the beginning of search1 to the end of search2 are replaced by replacement. There can be zero or more characters between search1 and search2. With replace2 unnested comments can be removed:

replace2("x := (*ord*) y;", "(*", "*)", "")  returns "x :=  y;"
Returns:
the result of the replacement.

upper

const func string: upper (in string: stri)

Convert a string to upper case. The conversion uses the default Unicode case mapping, where each character is considered in isolation. Characters without case mapping are left unchanged. The mapping is independend from the locale. Individual character case mappings cannot be reversed, because some characters have multiple characters that map to them.

Returns:
the string converted to upper case.

lower

const func string: lower (in string: stri)

Convert a string to lower case. The conversion uses the default Unicode case mapping, where each character is considered in isolation. Characters without case mapping are left unchanged. The mapping is independend from the locale. Individual character case mappings cannot be reversed, because some characters have multiple characters that map to them.

Returns:
the string converted to lower case.

trim

const func string: trim (in string: stri)

Return string with leading and trailing whitespace omitted. All characters less than or equal to ' ' (space) count as whitespace.

trim(" /n xyz /r")  returns "xyz"
Returns:
string with leading and trailing whitespace omitted.

ltrim

const func string: ltrim (in string: stri)

Return string with leading whitespace omitted. All characters less than or equal to ' ' (space) count as whitespace.

ltrim(" /n xyz /r")  returns "xyz /r"
Returns:
string with leading whitespace omitted.

rtrim

const func string: rtrim (in string: stri)

Return string with trailing whitespace omitted. All characters less than or equal to ' ' (space) count as whitespace.

rtrim(" /n xyz /r")  returns " /n xyz"
Returns:
string with trailing whitespace omitted.

trimValue

const func string: trimValue (in type: aType, in string: stri)

Trim a string such that it can be converted to aType. This function is overloaded for types where removing leading or trailing whitespace whould change the value.

integer parse trimValue(integer, " 1 ")   returns 1
Returns:
the trimmed string.

trimValue

const func string: trimValue (attr string, in string: stri)

Trim a string such that it can be converted to string. Leaves stri unchanged, since that would change the value.

string parse trimValue(string, " 1 ")   returns " 1 "
Returns:
the unchanged string.

str

const func string: str (in string: stri)

Convert to a string.

Returns:
its parameter unchanged.


 previous   up   next