Purpose |
Converts one or more numeric character codes (ANSI or UNICODE),
code ranges, and/or
|
Syntax |
s$ =
CHR$(expression [,expression] [,...]) |
Remarks |
The CHR$() form of the function creates a string of ANSI (1-byte) characters. Arguments must be ANSI (1-byte) characters, or codes in the range of 0 to 255. The CHR$$() form of the function creates a string of WIDE (2-byte) characters. Arguments must be WIDE (2-byte) characters, or codes in the range of 0 to 65535. Generally speaking, PowerBASIC handles ANSI/WIDE conversions for you, automatically and transparently. However, there are just a few functions (CHR$, PEEK$, POKE$, STRING$, etc.) which are ambiguous, by definition, and require that the programmer choose the appropriate result type (ANSI or WIDE). Use CHR$ for ANSI results, or use CHR$$ for Unicode results. In the remainder of these remarks, CHR$ is used to represent both CHR$ and CHR$$. CHR$ creates and returns a string. There are three forms of arguments available, and they may be intermixed in a single CHR$ function. The created string may contain no characters, one character, or multiple characters, depending upon the arguments you use. You may specify any number of arguments for this function. If the argument is a numeric expression, it is translated into the character defined by that number. A character code of -1 is treated as a special case. If you use it as an argument, CHR$ returns an empty (zero length) string for that character. For example, CHR$(65, -1, 66) returns "AB". CHR$(x& TO y&) returns a sequence of all characters from CHR$(x&) through CHR$(y&) inclusive. The characters may be ascending or descending in sequence. For example, CHR$(65 TO 70) returns the string "ABCDEF". CHR$(52 T0 50) returns the string "432", and CHR$(65 TO 65) returns the string "A". If the argument is a string expression, the characters are simply copied into the newly created string at the specified position. The expanded CHR$ definition is intended to assist in the encoding of longer strings, to avoid the need for concatenation operations. For example, the CHR$ function can be used to create COLLATE strings for the ARRAY SORT and ARRAY SCAN statements at run-time, and can be used to create string equates at compile time: $colstring = CHR$(0 TO 131, 97, 133 TO 255) The following lines are functionally equivalent, and return the same string result: a$ = CHR$("Line1", 13, 10, "Line2") a$ = "Line1" & CHR$(13) & CHR$(10) & "Line2" a$ = "Line1" & $CRLF & "Line2" CHR$ complements the ASC function, which returns the numeric character code of a nominated character in a string. |
See also |
ARRAY SCAN, ARRAY SORT, ASC function, ASC statement, NUL$, SPACE$, STRING$ |
Example |
H$ = CHR$("a$=", $DQ, 33, $DQ+$DQ, 35 TO 39, 40, $DQ) |
Result |
a$="!""#$%&'(" |