2.1.1. String Intrinsics

Version II.0, February 1979

2.1.1.1. Length

page117 FUNCTION LENGTH (STRING): INTEGER

Returns the integer value of the length of the STRING.

Example:

GEESTRING := '1234567';
WRITELN(LENGTH(GEEZTRING), ' ', LENGTH(''));
Will print:
7 0

2.1.1.2. Pos

FUNCTION POS(STRING, SOURCE): INTEGER

This function returns the position of the first occurrence of the pattern in SOURCE to be scanned. The INTEGER value of the position of the first character in the matched pattern will be returned; or if the pattern was not found, zero will be returned.

Example:

STUFF := 'TAKE THE BOTTLE WITH A METAL CAP';
PATTERN := 'TAL';
WRITELN(POS(PATTERN, STUFF));

Will print:

26

2.1.1.3. Concat

FUNCTION CONCAT(SOURCEs): STRING

There may be any number of source strings separated by commas. This function returns a string which is the concatenation of all the strings passed to it.

Example:

SHORTSTRING := 'THIS IS A STRING';
LONGSTRING := 'THIS IS A VERY LONG STRING.';
LONGSTRING := CONCAT('START ', SHORTSTRING, '-' , LONGSTRING);
WRITELN(LONGSTRING);

Will print: page118

START THIS IS A STRING-THIS IS A VERY LONG STRING.

2.1.1.4. Copy

FUNCTION COPY(SOURCE: STRING[*], INDEX: INTEGER, SIZE: INTEGER): STRING

This function returns a string containing SIZE characters copied from SOURCE starting at the INDEXth position in SOURCE.

Example:

TL := 'KEEP SOMETHING HERE';
KEPT := COPY(TL, POS('S', TL), 9);
WRITELN(KEPT);

Will print:

SOMETHING

2.1.1.5. Delete

PROCEDURE DELETE(VAR DESTINATION: STRING[*], INDEX: INTEGER, SIZE: INTEGER)

This procedure removes SIZE characters from DESTINATION starting at the INDEX specified.

Example:

OVERSTUFFED := 'THIS STRING HAS FAR TOO MANY CHARACTERS IN IT.';
DELETE(OVERSTUFFED, POS('HAS', OVERSTUFFED) + 3, 8);
WRITELN(OVERSTUFFED);

Will print:

THE STRING HAS MANY CHARACTERS IN IT.

2.1.1.6. Insert

PROCEDURE INSERT(SOURCE: STRING[*], VAR DESTINATION: STRING, INDEX: INTEGER)

This inserts SOURCE into DESTINATION at the INDXth position.

Example:

ID := 'INSERTIONS';
MORE := ' DEMONSTRATE';
DELETE(MORE, LENGTH(MORE), 1);
INSERT(MORE, ID, POS('IO', ID));
WRITELN(ID);
Will print:
INSERT DEMONSTRATIONS

2.1.1.7. Str

PROCEDURE STR(LONG: INTEGER[*], VAR DESTINATION: STRING[*])

page119 This converts the long integer LONG into a string. The resulting string is placed in DESTINATION. See section 3.3.3 for more about the use of long integers.

Example:

INTLONG := 102039503;
STR(INTLONG, INTSTRING);
INSERT('.' , INTSTRING, PRED(LENGTH(INTSTRING)));
WRITELN('$' ,INTSTRING);

Will print:

$1020395.03

2.1.1.8. String Integrity

In order to maintain the integrity of the LENGTH of a string, only string functions or full string assignments should be used to alter strings. Moves and/or single character assignments do not affect the length of a string which means it probably becomes wrong. The individual elements of STRING are of type CHAR and may be indexed
1..LENGTH(string)
Accessing the string outside this range will have unpredictable results if range-checking is off or cause a run-time error (1) if range checking is on.
page120
This page last regenerated Sun Jul 25 01:09:11 2010.