-
-
Notifications
You must be signed in to change notification settings - Fork 107
v2 Overview
axunonb edited this page Feb 6, 2022
·
1 revision
Install via Nuget: Install-Package SmartFormat.NET
Or, download the release manually: Releases
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"
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.
- Syntax, Terminology
- Placeholders and Nesting
- string.Format Compatibility
- Character Literals in Format Strings
- HTML With CSS or JavaScript
- Data Source Extensions
- Default _ DefaultFormatter
- Lists _ ListFormatter
- Choose _ ChooseFormatter
- Condition _ ConditionalFormatter
- Null _ NullFormatter
- SubString _ SubStringFormatter
- RegEx _ IsMatchFormatter
- Pluralization _ PluralLocalizationFormatter
- Localization _ LocalizationFormatter
- Templates _ TemplateFormatter
- TimeSpan _ TimeFormatter
- XML _ XElementFormatter
- Extension Methods
- Home
- Common Pitfalls
- HTML with CSS or JavaScript
- Overview
- Main Features
- Formatters
- Extra Features
- Console and StringBuilder
- TemplateFormatter
- SmartSettings to control Smart.Format behavior
- Additional Info
- License