Something went wrong. Try again.
A general purpose .. programming language written in zig ijadux2.tngl.sh/Rinnescript
zig language
Something went wrong. Try again.
1.7 kB · 43 lines
12345678910111213141516171819202122232425262728293031323334353637383940414243// strings.rg — formatting, escapes, and the string builtins//// Formatted output uses `{}` placeholders filled positionally from a `.{...}`// tuple; `{{`/`}}` escape literal braces. Plain `str` values concatenate// with `+`. The string builtins (trim, split, join, replace, to_lower,// to_upper, starts_with, ends_with, contains) are all function-style calls.//// Run: rinne run examples/strings.rg@import = .{ std };pub fn main() int { // ---- formatting ---- const name: str = "Rinne"; const n: int = 7; std.print("Hello, {}! You have {} items.\n", .{name, n}); std.print("Escaped braces: {{literal}} and {{}}\n", .{}); // ---- concatenation ---- const msg: str = "a" + "b" + "c"; std.print("concatenated: {}\n", .{msg}); // ---- builtins (function-style) ---- const s: str = " Hello, World! "; std.print("[{}]\n", .{std.strings.trim(s)}); // strip outer whitespace std.print("[{}]\n", .{std.strings.to_upper(s)}); // uppercase std.print("[{}]\n", .{std.strings.to_lower(s)}); // lowercase std.print("{}\n", .{std.strings.replace("a-b-c", "-", "_")}); // split into a []str; join back together. const parts = std.strings.split("one,two,three", ","); std.print("split={} -> join={}\n", .{ parts, std.strings.join(parts, "|") }); // predicates. std.print("start={} end={} contains={}\n", .{ std.strings.starts_with(s, " H"), std.strings.ends_with(s, "! "), std.strings.contains("abcdef", "cd"), }); // ---- length works on strings too ---- std.print("len(\"hello\")={}\n", .{std.strings.len("hello")}); return 0;}