Skip to content
axunonb edited this page Feb 6, 2022 · 1 revision

Getting Started

Install via Nuget: Install-Package SmartFormat.NET
Or, download the release manually: Releases

Usage example

It's as simple as:

using SmartFormat;
Smart.Format("{0} {1}", "Hello", "World") // outputs "Hello World"
Smart.Format("{h} {w}", new{ h = "Hello", w = "World" }) // outputs "Hello World"
Smart.Format("{0.ToUpper} {1.ToLower}", "Hello", "World") // outputs "HELLO world"

Template syntax overview

Literal text { expression [, align ] [: name(options) ] [: format ] }

Example: Smart.Format("There are {Length,7:default:000} items", items)
Outputs: "There are ____099 items"

  • expression is Length, which evaluates items.Length and gives us 99
  • align is 7, which causes the output to be padded with 4 extra spaces (shown as _ due to GitHub Markdown)
  • name is "default", which explicitly uses the DefaultFormatter. If omitted, the formatter will be chosen implicitly.
  • format is "000", which causes the number 99 to be padded with zeros.
Clone this wiki locally