Zig
Zig
Example: Crypt2.EncodeString method
Demonstrates how to call the EncodeString method.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
var s: [:0]const u8 = "Hello World";
std.debug.print("{s}\n", .{try crypt.encodeString(alloc, s, "utf-8", "hex")});
// Output: 48656C6C6F20576F726C64
std.debug.print("{s}\n", .{try crypt.encodeString(alloc, s, "utf-16", "hex")});
// Output: 480065006C006C006F00200057006F0072006C006400
std.debug.print("{s}\n", .{try crypt.encodeString(alloc, s, "utf-8", "base64")});
// Output: SGVsbG8gV29ybGQ=
s = "électricité";
std.debug.print("{s}\n", .{try crypt.encodeString(alloc, s, "utf-8", "hex")});
// Output: C3A96C6563747269636974C3A9
std.debug.print("{s}\n", .{try crypt.encodeString(alloc, s, "windows-1252", "hex")});
// Output: E96C6563747269636974E9
std.debug.print("{s}\n", .{try crypt.encodeString(alloc, s, "windows-1252", "hex_lower")});
// Output: e96c6563747269636974e9
std.debug.print("{s}\n", .{try crypt.encodeString(alloc, s, "utf-8", "url")});
// Output: %C3%A9lectricit%C3%A9
}