std/fmt
String formatting and padding utilities.
milo
from "std/fmt" import { fmt1, fmt2, join, padLeft, zeroPad }Example
milo
let msg = fmt2("Hello, {}! You have {} messages.", "Alice", "3")
// "Hello, Alice! You have 3 messages."
let id = zeroPad(42, 5) // "00042"
let row = padLeft("7", 3, 32) // " 7" (32 is ' ')
let csv = join(["a", "b"], ", ") // "a, b"API reference
fmt1
milo
pub fn fmt1(template: &string, a: &string): stringReplace the first {} with a.
fmt2
milo
pub fn fmt2(template: &string, a: &string, b: &string): stringReplace the first two {} with a and b.
fmt3
milo
pub fn fmt3(template: &string, a: &string, b: &string, c: &string): stringReplace the first three {} with a, b, and c.
fmt4
milo
pub fn fmt4(template: &string, a: &string, b: &string, c: &string, d: &string): stringReplace the first four {} with a, b, c, and d.
join
milo
pub fn join(parts: &Vec<string>, sep: &string): stringJoin a Vec<string> with a separator.
padLeft
milo
pub fn padLeft(s: &string, width: i64, ch: u8): stringLeft-pad a string to a minimum width.
padRight
milo
pub fn padRight(s: &string, width: i64, ch: u8): stringRight-pad a string to a minimum width.
zeroPad
milo
pub fn zeroPad(n: i64, width: i64): stringZero-pad an integer to a minimum width.