languages | products | page_type | name | urlFragment | description | |||
---|---|---|---|---|---|---|---|---|
|
|
sample |
.NET Core WinForms Formatting Utility (Visual Basic) |
windowsforms-formatting-utility-vb |
A .NET Core Windows Forms application written in Visual Basic that allows you to apply standard or custom format strings. |
The .NET Formating Utility (Formatter.exe) is a .NET Core Windows Forms application written in Visual Basic 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.
This sample is written in Visual Basic and targets .NET Core 3.0 running on Windows. It requires the .NET Core 3.0 SDK.
The source code includes an MSBuild project file for Visual Basic (a .vbproj file) that targets .NET Core 3.0. After you download the .zip file containing the example code, create a directory and Download the sample code files to your computer. To build the example:
-
Download the .zip file containing.
-
Create the directory to which you want to copy the files.
-
Copy the files from the .zip file to the directory you just created.
-
If you are using Visual Studio 2019:
-
In Visual Studio, select Open a project or solution (or File > Open > Project/Solution from the Visual Studio menu.
-
Select Debug > Start Debugging from the Visual Studio menu to build and launch the application.
-
-
If you are working from the command line:
-
Navigate to the directory that contains the sample.
-
Type in the command
dotnet run
to build and launch the application.
-
Formatting involves converting a value to its string representation. ToString
methods that include a string parameter, interpolated strings, as well as the composite formatting feature supported by such methods as String.Format, StringBuilder.AppendFormat, 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)
Frequently, though, developers forget what standard and custom format specifiers are available, and they 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. By default, numbers and dates use the formatting conventions of the current culture, though you can also select a culture whose formatting conventions you'd like to use. A text box then displays the result 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 information on formatting in .NET, see: