std/fmt
String formatting and padding utilities.
milo
from "std/fmt" import { fmt1, fmt2, join, padLeft, zeroPad }Functions
fmt1
milo
fn fmt1(template: &string, a: &string): stringReplaces the first {} in template with a.
fmt2
milo
fn fmt2(template: &string, a: &string, b: &string): stringReplaces the first two {} placeholders with a and b.
milo
let msg = fmt2(&"Hello, {}! You have {} messages.", &name, &intToString(count))
// "Hello, Alice! You have 3 messages."fmt3
milo
fn fmt3(template: &string, a: &string, b: &string, c: &string): stringReplaces the first three {} placeholders.
fmt4
milo
fn fmt4(template: &string, a: &string, b: &string, c: &string, d: &string): stringReplaces the first four {} placeholders.
padLeft
milo
fn padLeft(s: &string, width: i64, fill: u8): stringPads s on the left with fill until it reaches width.
padRight
milo
fn padRight(s: &string, width: i64, fill: u8): stringPads s on the right with fill until it reaches width.
zeroPad
milo
fn zeroPad(n: i64, width: i64): stringFormats integer n as a string, zero-padded to width digits.
milo
let s = zeroPad(42, 5)
// "00042"join
milo
fn join(parts: &Vec<string>, separator: &string): stringJoins all strings in parts with separator between them.
milo
let csv = join(&names, &", ")