Format package
The Format package provides support for formatting strings. It can be used to set things like width, padding and alignment, as well as controlling the way numbers are displayed (decimal, octal, hexadecimal).
Example program
use "format" actor Main fun disp(desc: String, v: I32, fmt: FormatInt = FormatDefault): String => Format(desc where width = 10) + ":" + Format.int[I32](v where width = 10, align = AlignRight, fmt = fmt) new create(env: Env) => try (let x, let y) = (env.args(1)?.i32()?, env.args(2)?.i32()?) env.out.print(disp("x", x)) env.out.print(disp("y", y)) env.out.print(disp("hex(x)", x, FormatHex)) env.out.print(disp("hex(y)", y, FormatHex)) env.out.print(disp("x * y", x * y)) else let exe = try env.args(0)? else "fmt_example" end env.err.print("Usage: " + exe + " NUMBER1 NUMBER2") end
Public Types
- trait PrefixSpec
- primitive PrefixDefault
- primitive PrefixSpace
- primitive PrefixSign
- type PrefixNumber
- trait FormatSpec
- primitive FormatDefault
- primitive FormatUTF32
- primitive FormatBinary
- primitive FormatBinaryBare
- primitive FormatOctal
- primitive FormatOctalBare
- primitive FormatHex
- primitive FormatHexBare
- primitive FormatHexSmall
- primitive FormatHexSmallBare
- type FormatInt
- primitive FormatExp
- primitive FormatExpLarge
- primitive FormatFix
- primitive FormatFixLarge
- primitive FormatGeneral
- primitive FormatGeneralLarge
- type FormatFloat
- primitive Format
- primitive AlignLeft
- primitive AlignRight
- primitive AlignCenter
- type Align
© 2016-2020, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/format--index