Character codes: Difference between revisions

Added Neko
(Add Emacs lisp solution)
(Added Neko)
Line 1,081:
 
 
=={{header|MUMPS}}==
<lang MUMPS>WRITE $ASCII("M")
WRITE $CHAR(77)</lang>
 
 
=={{header|Neko}}==
Neko treats strings as an array of bytes
 
<lang neko>// An 'a' and a 'b'
var s = "a";
var c = 98;
var h = " ";
 
$print("Character code for 'a': ", $sget(s, 0), "\n");
=={{header|MUMPS}}==
 
<lang MUMPS>WRITE $ASCII("M")
$sset(h, 0, c);
WRITE $CHAR(77)</lang>
$print("Character code ", c, ": ", h, "\n");</lang>
 
{{out}}
<pre>Character code for 'a': 97
Character code 98: b</pre>
 
Neko also has standard primitives for handling the byte array as UTF-8
 
<lang neko>// While Neko also includes some UTF-8 operations,
// native strings are just arrays of bytes
var us = "¥·£·€·$·¢·₡·₢·₣·₤·₥·₦·₧·₨·₩·₪·₫·₭·₮·₯·₹";
 
// load some Std lib primitives
utfGet = $loader.loadprim("std@utf8_get", 2);
utfSub = $loader.loadprim("std@utf8_sub", 3);
utfAlloc = $loader.loadprim("std@utf8_buf_alloc", 1);
utfAdd = $loader.loadprim("std@utf8_buf_add", 2);
utfContent = $loader.loadprim("std@utf8_buf_content", 1);
 
// Pull out the Euro currency symbol from the UTF-8 currency sampler
var uc = utfGet(us, 4);
$print("UFT-8 code for '", utfSub(us, 4, 1), "': ", uc, "\n");
 
// Build a UTF-8 buffer
var buf = utfAlloc(4);
 
// Add a Pound Sterling symbol
uc = 8356;
utfAdd(buf, uc);
$print("UTF-8 code ", uc, ": ", utfContent(buf), "\n");</lang>
 
{{out}}
<pre>UFT-8 code for '€': 8364
UTF-8 code 8356: ₤</pre>
 
=={{header|NESL}}==
Anonymous user