Sample code for 30+ languages & platforms
Zig

StringBuilder GetNth

Demonstrates the GetNth method.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // The GetNth method is handy for getting parts from delimited strings.
    // For example:

    const sb = try chilkat.StringBuilder.init();
    defer sb.deinit();
    sb.append("red,blue,\"green,purple\",,yellow") catch {};

    const delimiter_char = ",";
    const except_double_quoted = true;
    const except_escaped = true;

    // Prints "[red]"
    std.debug.print("[{s}]\n", .{try sb.getNth(alloc, 0, delimiter_char, except_double_quoted, except_escaped)});

    // Prints "[blue]"
    std.debug.print("[{s}]\n", .{try sb.getNth(alloc, 1, delimiter_char, except_double_quoted, except_escaped)});

    // Prints "[green,purple]"
    std.debug.print("[{s}]\n", .{try sb.getNth(alloc, 2, delimiter_char, except_double_quoted, except_escaped)});

    // Prints "[]"
    std.debug.print("[{s}]\n", .{try sb.getNth(alloc, 3, delimiter_char, except_double_quoted, except_escaped)});

    // Prints "[yellow]"
    std.debug.print("[{s}]\n", .{try sb.getNth(alloc, 4, delimiter_char, except_double_quoted, except_escaped)});

    // Prints "[]"
    std.debug.print("[{s}]\n", .{try sb.getNth(alloc, 5, delimiter_char, except_double_quoted, except_escaped)});
}