Library Routines
1. String and Character Functions
These routines handle the manipulation of STRING and CHAR data types.
| Routine & Syntax | Description |
|---|---|
| LEFT(ThisString: STRING, x: INTEGER) RETURNS STRING | Returns the leftmost x characters from ThisString. Example: LEFT("ABCDEFGH", 3) returns "ABC" |
| RIGHT(ThisString: STRING, x: INTEGER) RETURNS STRING | Returns the rightmost x characters from ThisString. Example: RIGHT("ABCDEFGH", 3) returns "FGH" |
| MID(ThisString: STRING, x: INTEGER, y: INTEGER) RETURNS STRING | Returns a string of length y starting at position x from ThisString. Example: MID("ABCDEFGH", 2, 3) returns "BCD" |
| LENGTH(ThisString: STRING) RETURNS INTEGER | Returns the integer value representing the length of ThisString. Example: LENGTH("Happy Days") returns 10 |
| TO_UPPER(x: <datatype>) RETURNS <datatype> | Converts all characters in x (CHAR or STRING) to upper case. Example: TO_UPPER("Error 803") returns "ERROR 803" |
| TO_LOWER(x: <datatype>) RETURNS <datatype> | Converts all characters in x (CHAR or STRING) to lower case. Example: TO_LOWER("JIM 803") returns "jim 803" |
2. Data Conversion Functions
Routines used to convert values between numeric and string formats.
| Routine & Syntax | Description |
|---|---|
| NUM_TO_STR(x: REAL/INTEGER) RETURNS STRING | Returns a string representation of a numeric value. Example: NUM_TO_STR(87.5) returns "87.5" |
| STR_TO_NUM(x: STRING/CHAR) RETURNS REAL/INTEGER | Returns a numeric representation of a string. Example: STR_TO_NUM("23.45") returns 23.45 |
| IS_NUM(ThisString: STRING/CHAR) RETURNS BOOLEAN | Returns TRUE if ThisString represents a valid numeric value. Example: IS_NUM("-12.36") returns TRUE |
| ASC(ThisChar: CHAR) RETURNS INTEGER | Returns the integer ASCII value of a character. Example: ASC('A') returns 65 |
| CHR(x: INTEGER) RETURNS CHAR | Returns the character whose ASCII value is x. Example: CHR(65) returns 'A' |
3. Numeric & Date Functions
Routines for mathematical operations and date processing.
| Routine & Syntax | Description |
|---|---|
| INT(x: REAL) RETURNS INTEGER | Returns the integer part of x. Example: INT(27.5415) returns 27 |
| RAND(x: INTEGER) RETURNS REAL | Returns a real number in the range 0 to x (not inclusive of x). Example: RAND(87) could return 35.430729 |
| DAY(ThisDate: DATE) RETURNS INTEGER | Returns the day number from ThisDate. Example: DAY(04/10/2003) returns 4 |
| DAYINDEX(ThisDate: DATE) RETURNS INTEGER | Returns the day index where Sunday = 1, Monday = 2, etc. Example: DAYINDEX(09/05/2023) returns 3 |
| TODAY() RETURNS DATE | Returns the current system date. |
⚠️ Exam Note (Text Files):
EOF(FileName: STRING) RETURNS BOOLEAN returns TRUE if there are no more lines to read. The file must be open in READ mode.