Character codes: Difference between revisions
→{{header|Zig}}: update to use main() and stdout
No edit summary |
Recombinant (talk | contribs) (→{{header|Zig}}: update to use main() and stdout) |
||
Line 2,753:
=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");
const unicode = std.unicode;
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try characterAsciiCodes(stdout);
try characterUnicodeCodes(stdout);
}
fn characterAsciiCodes(writer: anytype) !void {
try writer.writeAll("Sample ASCII characters and codes:\n");
// Zig's string is just an array of bytes (u8).
const message: []const u8 = "ABCabc";
for (message) |val| {
}
try writer.writeByte('\n');
}
fn characterUnicodeCodes(writer: anytype) !void {
try writer.writeAll("Sample Unicode characters and codes:\n");
const message: []const u8 = "あいうえお";
const utf8_view = unicode.Utf8View.initUnchecked(message);
Line 2,778 ⟶ 2,784:
while (iter.nextCodepoint()) |val| {
var array: [4]u8 = undefined;
}
try writer.writeByte('\n');
}</syntaxhighlight>
{{out}}
<pre>
'A' code: 65 [hexa: 0x41]
'B' code: 66 [hexa: 0x42]
Line 2,792 ⟶ 2,799:
'b' code: 98 [hexa: 0x62]
'c' code: 99 [hexa: 0x63]
Sample Unicode characters and codes:
'あ' code: 12354 [hexa: U+3042]
'い' code: 12356 [hexa: U+3044]
'う' code: 12358 [hexa: U+3046]
'え' code: 12360 [hexa: U+3048]
'お' code: 12362 [hexa: U+304a]</pre>
=={{header|zkl}}==
The character set is 8 bit ASCII (but doesn't care if you use UTF-8 or unicode characters).
|