Zig
Zig
URL Encoding and Decoding
Demonstrates URL encoding/decoding using the HTTP convenience methods.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 http = try chilkat.Http.init();
defer http.deinit();
const s = "Hello World! 100% sure.";
const encoded = try http.urlEncode(alloc, s);
std.debug.print("URL encoded: {s}\n", .{encoded});
// Space → %20
// ! → %21
// % → %25
const decoded = try http.urlDecode(alloc, encoded);
std.debug.print("URL decoded: {s}\n", .{decoded});
// Output:
// URL encoded: Hello%20World%21%20100%25%20sure.
// URL decoded: Hello World! 100% sure.
}