Is Smart.Format compatible with string.Format? | Localization | 0.9.0-preview
docs.unity3d.com
    Show / Hide Table of Contents

    Is Smart.Format compatible with string.Format?

    Absolutely. The core of Smart.Format supports all the features of String.Format. You can read about the standard features of String.Format [[at Microsoft's Composite Formatting reference page|http://msdn.microsoft.com/en-us/library/txafckwd.aspx]]. The main features are:

    Numbered Placeholders

    Numbers correspond to the argument index:

    Smart.Format("{0} {1}", "Hello", "World");
    // Outputs: "Hello World"
    

    Item Formats

    Determines how to format items, such as numbers and dates:

    Smart.Format("{0:N3} | {1:MMMM, yyyy}", 5.5, new DateTime(2010,3,4));
    // Outputs: "5.500 | March, 2010"
    

    Alignment

    Inserts spaces before or after the item, aligning it with other items:

    Smart.Format("|{0,-10}|{1,10}|", "Left", "Right");
    // Outputs: "|Left      |     Right|"
    

    Brace Escaping

    Escape braces using double-braces:

    Smart.Format("{{0}} {{{0}}} {{}}", "Zero");
    // Outputs: "{0} {Zero} {}"
    

    Localization

    Smart.Format uses the current culture info for formatting, or you can supply your own IFormatProvider:

    Smart.Format(CultureInfo.GetCultureInfo("en-US"), "{0:C}", 1234) // Outputs: "$1,234.00"
    Smart.Format(CultureInfo.GetCultureInfo("ja-JP"), "{0:C}", 1234) // Outputs: "¥1234"
    
    In This Article
    • Numbered Placeholders
    • Item Formats
    • Alignment
    • Brace Escaping
    • Localization
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023