v2 Overview - axuno/SmartFormat GitHub Wiki
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 evaluatesitems.Length
and gives us99
- 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 theDefaultFormatter
. If omitted, the formatter will be chosen implicitly. - format is
"000"
, which causes the number99
to be padded with zeros.