5 Operators and Functions
Built-In String Functions
The built-in string functions available are:
- CHR$ (X)
- Returns the ASCII character-equivalent of the numeric expression X MOD 256 (a number from 0 through 255). For example, CHR$(65) = "A". ASCII decimal equivalents are listed in page 391 .
- ERRMSG$ (error number)
- Returns error description of given error number. The error messages are located in the message catalog file eloq.cat which will be located at the standard NLS path.
- Example:
DISP ERRMSG$(2)
"Memory overflow"
- Error handling:
- ERRMSG$ will not bring a program error if either message or message catalog could not be found, to avoid looping in the error handler.
- Instead it will return an error message which will contain the error number and a descriptive text where '#' will replaced by the error number parameter:
(ERR#): Message catalog not found
(ERR#): Error message not found
- GETENV$ (S$)
- Returns the value of environment variable.
- MAPPNTR$ (printer)
- Returns printer mapping. This is necessary if you use TIO and you want to configure the device using stty because PORT number may be configured to any devicefile.
- Return values:
NONEXISTENT
if this printer is not available
INTERNAL
if printer is 9 or 10 (and local printer available)
PIPE
if printer is mapped to a pipe
"/dev/"
- if printer is mapped to a (device-)file
- It may also be used to check for existing printers.
- Sample program sequence:
COMMAND "!stty 2400 icanon <"&MAPPNTR$(15)
- This will configure device mapped to PRINTER/PORT 15 to use icanon mode at 2400 baud.
- MAPVOL$(Volspec$)
- Returns hp-ux path of mapped volume name or device specifier.
- REVISION$
- Returns Eloquence revision.
- SYSID$
- Returns the revision of the used operating system.
- RPT$ (S$,X)
- Takes the string S$ and repeats it X times. If X = 0 a null string is returned.
- TRIM$ (S$)
- Returns a string which is equal to S$ with all leading and trailing blanks stripped off.
- VAL$ (X)
- Converts the value of the numeric expression X to its corresponding string of ASCII digits. For example, VAL$ (65) = "65".
- LWC$ (S$)
- Returns a string with all characters converted to lowercase.
- UPC$ (S$)
- Returns a string with all characters converted to uppercase.
- TYPEOF$(X)
- Returns the name of the type of the given User Defined variable.
A number, not a string, is returned by the following functions:
- LEN (S$)
- Returns the number of ASCII characters in the string S$.
- LEX (S$,T$)
- Compares the string S$ with the second string T$ and returns -1 if S$ is less than T$; 0 if S$ equals T$; 1 if S$ is greater than T$.
- NUM (S$)
- Returns a numeric value between 0 and 255 corresponding to the first character of the string S$. For example, NUM ("A") = 65.
- POS (S$,T$)
- Searches the string S$ for the first occurrence of the string T$. Returns the starting position (index) if found; otherwise returns 0.
- SCAN (S$,T$)
- Searches the string S$ for the first occurrence of any single character in the string T$. Returns the starting position (index) if found; otherwise returns 0.
- VAL (S$)
- Returns the numeric equivalent of the string S$, which must be a string of ASCII digits. (S$ may include a decimal point.) For example, VAL ("1") = 1. The argument may be any string that begins with a valid number (integer or real). VAL will return the value of this number and ignore any remainder of the string. VAL ("1.2 ABC") will return the value 1.2; VAL ignores the "ABC". If a string begins with anything other than an integer or real, ERROR 32 will result.
Some functions are available for compatibility reasons, only. To get the syntax of this functions, see section , Built-in String Function, on page 4
Most of the string functions are used to manipulate and create strings. For example:
10 String$="REPEAT"
20 PRINT RPT$(String$,10)
30 T$=" PART NO. "
40 PRINT T$;"*";TRIM$(T$);"*"
REPEATREPEATREPEATREPEATREPEATREPEATREPEATREPEATREPEATREPEAT
PART NO. *PART NO.*
no leading or trailing blanks here
50 S$="STRING"
60 PRINT S$,LEN(S$)
70 S$[LEN(S$)+1]="FUNCTIONS "
80 PRINT RPT$(LWC$(S$),4)
STRING 6
stringfunctionsstringfunctionsstringfunctionsstringfunctions
90 T$="TELEVISION"
100 V$="VISION"
110 PRINT T$,POS(T$,V$)
TELEVISION 5
120 T$[POS(T$,"V")]=UPC$("phones")
130 PRINT T$
140 Invent$=V$T$[POS(T$,"P")]
150 PRINT Invent$,LWC$(Invent$)
160 END
TELEPHONES
VISIONPHONES visionphones
VAL$ and VAL are used to go back and forth between strings of ASCII digits ("1234") and numeric values. VAL$ results are returned in the current output format (FIXED, FLOAT or STANDARD). For example:
10 DIM Pay$[50]
20 FIXED 2
30 Pay$="BASE: 295.50 TAX: 125.30"
40 Takehome=VAL(Pay$[7,12])-VAL(Pay$[19,24])
50 PRINT Pay$, "BUT YOU GET:";Takehome
60 Pay$[25]=" TAKEHOME: "VAL$(Takehome)
70 PRINT LWC$(Pay$)
80 END
produces
BASE: 295.50 TAX: 125.30 BUT YOU GET: 170.20
base: 295.50 tax: 125.30 takehome: 170.20
NUM and CHR$ are used to go back and forth between an ASCII character and its ASCII index. For example, this program tests the numeric value of each character in the string Test$ to see if it contains an integer:
10 FOR I = 1 to LEN(Test$)
20 IF NUM(Test$[I]) < 48 OR NUM(Test$[I]) > 57 THEN
30 PRINT VAL(Test$);" is not an integer"
50 END IF
50 NEXT I
60 END
Here is a simple program which displays each standard ASCII character and its decimal ASCII code.
110 FOR Char=32 TO 127
120 DISP Char;CHR$(Char);SPA(3);
130 NEXT Char
140 END
RUN
32 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' 40 ( 41 )
42 * 43 + 44 , 45 - 46 . 47 / 48 0 49 1 50 2 51 3
52 4 53 5 54 6 55 7 56 8 57 9 58 : 59 ; 60 < 61 =
62 > 63 ? 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G
72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O 80 P 81 Q
82 R 83 S 84 T 85 U 86 V 87 W 88 X 89 Y 90 Z 91 [
92 \ 93 ] 94 ^ 95 _ 96 97 a 98 b 99 c 100 d 101 e
102 f 103 g 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o
112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w 120 x 121 y
122 z 123 { 124 | 125 } 126 ~ 127
Outputting decimal character values below 32 sends ASCII control codes such as FF (form feed) and CR (carriage return). Sending character values above 127 enables program control of display enhancements and alternate characters on the display. Refer to page 249 for more details.
The SYSID$ Function
The SYSID$ function is a user-definable system identifier. Using the capability of HP 9000s to communicate asynchronously with each other, a user can configure one system's terminal to act as a terminal on another. In a more complex network, the user on the first system may be linked to the second system, then to the third system, and so on. In order to determine which system the user is on, use the system identifier function--SYSID$.
The syntax for the SYSID$ function is as follows:
SYSID$
The system identifier will return a string of max. 20 characters in length.
NOTE: The Eloquence SYSID$ function returns the same information as the HP-UX uname command. In the HP-UX environment the term "hostname" is used instead of "system identifier". The HP-UX command to display the hostname is as follows:
uname -n
Eloquence Language Manual - 19 DEC 2002