| CARVIEW |
Select Language
HTTP/2 200
date: Wed, 31 Dec 2025 04:54:18 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"9a6f8d3c6b63be139b2c581ef5f4e981"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=B8r%2BftNAVZFv%2Fdhwwuh7YGbov4BmmDnK4ZwAY3IH7ldQKWDmpOjqZFE3rTd5Sb7bbxXbexPaopf%2B7BR01aySArLLwBcJzFqbDWOHcv4kZtDgW7GPPxVyqj9JrSAFYJGWBtmryhoooHCAt7TaALsxxYnmwAI4qY99Pwf45krJr2p6M4rXehAqxUwOj%2F79CxZEJqHHw%2FPXO1fWM2Ul5ia0NBzd6ozcLfFwOBA9OygSN%2F1RTEsa%2BzbEH%2BpBuaWKz5f0YxS3ds7WLHyryPI6GAGK6w%3D%3D--WpOMkbr0fhf8plkD--4Czkh%2B8DOqXPlwjibBBJcg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1980665068.1767156858; Path=/; Domain=github.com; Expires=Thu, 31 Dec 2026 04:54:18 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 31 Dec 2026 04:54:18 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: A916:192164:14995F7:17674D7:6954AC7A
Home · axuno/SmartFormat Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 106
Home
axunonb edited this page Mar 12, 2022
·
110 revisions
SmartFormat is a lightweight text templating library written in C#.
It can format various data sources into a string with a minimal, intuitive syntax similar to string.Format. All formatting takes place at runtime.
SmartFormat uses extensions to provide named placeholders, localization, pluralization, gender conjugation, as well as list and time formatting. Formatting extensions can be nested.
Custom source or formatter extensions can be added easily using simple interfaces.
- High performance with low memory footprint
- Minimal, intuitive syntax
- Formatting takes place exclusively at runtime
- Exact control of whitespace text output
-
string.Formatcompatibility mode andSmart.Formatenhanced mode - Most common data sources work out-of-the-box
- Many built-in formatting extensions
- Custom formatting and source extensions are easy to integrate
- Comprehensive documentation: current Wiki, complete xmldoc
var data = new { Library = "SmartFormat"};
_ = Smart.Format("Composed with {Library}.", data);
// Result: "Composed with SmartFormat."var stringFormat = string.Format("{0} {0:N2} {1:yyyy-MM-dd}", 5, new DateTime(1900, 12, 31));
var smartFormat = Smart.Format("{0} {0:N2} {1:yyyy-MM-dd}", 5, new DateTime(1900, 12, 31));
// Result: (stringFormat == smartFormat) == truevar data = new [] {1, 2, 3, 4, 5};
_ = Smart.Format("{0:list:N2|, |, and }.", (object) data);
// Result: "1.00, 2.00, 3.00, 4.00, and 5.00."var data = new[] { new { Name = "John", Gender = 0 },
new { Name = "Mary", Gender = 1 } };
_ = Smart.Format("{Name} commented on {Gender:choose:his|her} photo", data[1]);
// Result: "Mary commented on her photo"Formatters can be nested. In this example we have
- a
ListFormatter - with a nested
ListFormatter - which has a nested
DefaultFormatter
var data = new List<int[]> {
new[] { 1, 2, 3 },
new[] { 4, 5, 6 },
new[] { 7, 8, 9 }
};
// "list" is the formatter name
_ = Smart.Format("{0:list:Elements\\: {:list:{:000}|, |, }|\n|\n}", data);
// | | | | | |
// | | element format | |
// | |___ inner list ___| |
// |_______________________ outer list __________|
/* Result:
Elements: 001, 002, 003
Elements: 004, 005, 006
Elements: 007, 008, 009
*/Keep on reading.
- 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
Clone this wiki locally
You can’t perform that action at this time.
3.6