ASCII control characters: Difference between revisions
Created Nim solution.
(Created Nim solution.) |
|||
Line 361:
del::Control = 127
(CNTRL.nul, CNTRL.ht, CNTRL.us, CNTRL.del) = (0, 9, 31, 127)
</pre>
=={{header|Nim}}==
We define an enumeration type.
For each element, Nim allows to specify its integer value and its string representation. Here, the integer value is implicit (starting from zero) except for DEL whose value must be specified. As we use the standard names for the elements, we don’t have to specify the string representation.
The integer value is obtained with function <code>ord</code> and the string representation with function<code>$</code>.
<syntaxhighlight lang="Nim">import std/strutils
type AsciiControlChar {.pure.} = enum NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL,
BS, HT, LF, VT, FF, CR, SO, SI,
DLE, DC1, DC2, DC3, DC4, NAK, SYN, ETB,
CAN, EM, SUB, ESC, FS, GS, RS, US,
SP, DEL = 0x7F
echo ' ', CR, " = ", ord(CR).toHex(2)
echo DEL, " = ", ord(DEL).toHex(2)
</syntaxhighlight>
{{out}}
<pre> CR = 0D
DEL = 7F
</pre>
|