.NET Framework 4 Formatting Utility


.NET Framework, CLR, .NET Framework 4.0
.NET Framework formatting
Desktop
en-US
3/10/2012

Introduction

The Format Utility (Formatter.exe) is a Windows Forms application that allows you to apply standard or custom format strings to either numeric values or date and time values and to determine how they affect the result string.

Building the Sample

The example is packaged with an MSBuild project file that targets the .NET Framework Version 4. Download the sample code files to your computer. Open the solution (Formatter.sln) in Visual Studio 2010 and build the solution.

Description

Formatting involves converting a value to its string representation. The overloaded ToString method as well as the composite formatting feature supported by the String.Format method, the StringBuilder.AppendFormat method, the Console output methods, and the stream output methods give developers control over the string representations of numbers and dates. They allow such code as: 

Console.WriteLine("{0:YYYY-MM-dd}", thisDate);

or

Dim piString As String = Math.PI("r")

Frequently, though, developers forget what standard and custom format specifiers are available, and tehy forget how a particular format string is reflected in the result string. The Format Utility (Formatter.exe) allows you to enter a source value, indicate whether it is a number or a date and time value, and select a standard format string from a drop-down list or enter a custom format string in a text box. A text box then displays the result string, which is interpreted using the conventions of the current culture.

A drop-down combo box allows you to either select one of the supported standard format strings, or you can enter your own standard or custom format string. Note that the standard numeric format strings do not include precision specifiers; if you want to include a precision specifier in a format string, you must enter it yourself.

For an overview of formatting support in the .NET Framework, see Formatting Types.

Source Code Files

The Format Utility (Formatter.exe) is a Windows Forms application that consists of the following project files:

More Information

For additional information about standard and custom format strings in the .NET Framework, see Standard Numeric Format Strings, Custom Numeric Format Strings, Standard Date and Time Format Strings, and Custom Date and Time Format Strings.