Format string

xiaoxiao2021-03-06  72

String.Format (String Format, params object [])

MSDN: Will specify

The format item in the string is replaced with the corresponding array.

The text equivalent of the value of the Object instance.

Note

For more information on formatting, see

Format type

with

Format overview

. For more information on composite formatting features of Format support, see

Composite formatting

.

Embed Format parameters with zero or more format items (format {index [, alignment] [: formatstring]}), where:

Index

From zero start integers, indicating elements that are formatted in the object list. If the object specified by the index is an empty reference (Visual Basic

Nothing), the format item will be replaced by a null string ("").

Alignment

Optional integer, indicating the minimum width of the area that contains the formatted value. If the length of the format value is less than alignment, the area is filled with a space. If alignment is negative, the formatted value will be aligned in the area; if it is positive, the formatted value will be aligned. If no alignment is specified, the length of the region is the length of the format value. If you specify alignment, you need to separate with a comma.

FormatString

The optional string of formatted code. If FORMATSTRING is not specified, the corresponding parameters are implemented

Iformattable interface, the empty reference is empty.

Nothing)

IFORMATTABLE.TOSTRING format string. therefore,

All implementations for iformattable.toString must allow empty references (

Nothing) As a format string,

String's form returns the default format settings for object representations. If you specify formatString, you must use a colon.

The front guided brace characters and suffix braces must be used, ie "{" and "}". To specify a single brace character in Format, specify two leading brace characters or suffix braces characters (ie "{{" or "}}").

If Format is "Thank you for your purchase of {0: ####} Copies of Microsoft® .NET (Core Reference).", And arg [0] is int16 having a value of 123, the return value is:

"Thank you for your purchase of 123 COPIES OF Microsoft® .NET (Core Reference)."

If the Format value is "BRAD's DOG HAS {0, -8: g} FleaS.", The arg [0] is an int16 (in this example, the underscore means filling space), then the return value is:

"BRAD'S DOG HAS 42______ fleas."

转载请注明原文地址:https://www.9cbs.com/read-88078.html

New Post(0)