String. Usage of format

Source: Internet
Author: User
Tags iso 8601 local time

1. Formatted currency (related to system environment, Chinese system default format RMB, English system format USD)

String. Format ("{0:c}", 0.2) results are: ¥0.20 (English operating system results: $0.20)

The default formatting retains two decimal places after the decimal point, and if you need to keep one or more, you can specify the number of digits
String. Format ("{0:c1}", 23.15) Result: ¥23.2 (intercept will be automatically rounded)

Formatting multiple instances of object
String. Format ("market price: {0:C}, preferential price {1:C}", 23.15,19.82)

2, formatted decimal number (formatted as a fixed number of digits, the number of digits can not be less than unformatted before, only support shaping)

String. Format ("{0:d3}", 23) result is: 023

String. The result of Format ("{0:d2}", 1223) is: 1223, (the precision specifier indicates the minimum number of digits required in the resulting string.) )

3. A semicolon-delimited number, and specify the number of digits after the decimal point

String. Format ("{0:n}", 14200) Results: 14,200.00 (default is two digits after decimal point)

String. Format ("{0:n3}", 14200.2458) Result: 14,200.246 (auto rounding)

4. Percentage of formatting

String. Format ("{0:p}", 0.24583) result is: 24.58% (default of two decimal places reserved)

String. Format ("{0:p1}", 0.24583) result is: 24.6% (auto rounding)

5, zero placeholder and digit placeholder

String. The result of Format ("{0:0000.00}", 12394.039) is: 12394.04

String. The result of Format ("{0:0000.00}", 194.039) is: 0194.04

String. Format ("{0:###.##}", 12394.039) result is: 12394.04

String. Format ("{0:####.#}", 194.039) result is: 194

The following explanation is difficult to understand, more test the actual application can be understood.
Zero placeholder:
If the formatted value has a number in the format string where "0" appears, this number is copied to the result string. The position of the leftmost "0" before the decimal point and the rightmost "0" after the decimal point determine the total number range that appears in the result string.
The "00" specifier causes the value to be rounded to the nearest digit before the decimal point, where 0 bits are always removed.

Digit placeholder:
If the formatted value has a number in the format string where "#" appears, the number is copied to the result string. Otherwise, no value is stored at this location in the resulting string.
Note that if "0" is not a valid number, this specifier never displays the "0" character, even if "0" is the only number in the string. If "0" is a valid number in the displayed number, the "0" character is displayed.
The "# #" format string allows the value to be rounded to the nearest digit before the decimal point, where 0 is always removed.

6. Date formatting

String. Format ("{0:d}", System.DateTime.Now) result is: 2009-3-20 (month position is not 03)

String. Format ("{0:d}", System.DateTime.Now) results are: March 20, 2009

String. Format ("{0:f}", System.DateTime.Now) results are: March 20, 2009 15:37

String. Format ("{0:f}", System.DateTime.Now) results are: March 20, 2009 15:37:52

String. Format ("{0:g}", System.DateTime.Now) results are: 2009-3-20 15:38

String. Format ("{0:g}", System.DateTime.Now) results are: 2009-3-20 15:39:27

String. Format ("{0:m}", System.DateTime.Now) results are: March 20

String. The result of Format ("{0:t}", System.DateTime.Now) is: 15:41

String. The result of Format ("{0:t}", System.DateTime.Now) is: 15:41:50


For more detailed instructions please follow Microsoft's instructions on this or inquire on MSDN.

Standard numeric format string

Format specifier name description
C or C
Currency
The number is converted to a string that represents the monetary amount. The conversion is controlled by the currency format information of the current NumberFormatInfo object.

The precision specifier indicates the desired number of decimal digits. If the precision specifier is omitted, the default currency precision given by the current NumberFormatInfo object is used.

D or D
Decimal number
This format is supported only for integer types. A string that is converted to a decimal number (0-9), preceded by a minus sign, if the number is negative.

The precision specifier indicates the minimum number of digits required in the resulting string. If necessary, fill the left side of the number with 0 to produce the number of digits given by the precision specifier.

E or E
Science Notation (index)
The number is converted to "-d.ddd ... A string in the form of e+ddd "or"-d.ddd...e+ddd ", where each" D "represents a number (0-9). If the number is negative, the string begins with a minus sign. There is always a number before the decimal point.

The precision specifier indicates the number of digits required after the decimal point. If the precision specifier is omitted, the default value, six digits after the decimal point, is used.

The case of the format specifier indicates whether to prefix "E" or "E" before the exponent. The index is always composed of a plus or minus sign and a minimum of three digits. If required, fill the index with 0 to meet the requirement of a minimum of three digits.

F or F
Sentinel
The number is converted to a string in the form "-ddd.ddd ...", where each "D" represents a number (0-9). If the number is negative, the string begins with a minus sign.

The precision specifier indicates the desired number of decimal digits. If the precision specifier is omitted, the default numeric precision given by the current NumberFormatInfo object is used.

G or G
Conventional
Depending on the number type and whether there is a precision specifier, the number is converted to the most compact form of a fixed-point or scientific notation. If the precision specifier is omitted or zero, the type of the number determines the default precision, as shown in the following table.

? Byte or Sbyte:3

? Int16 or Uint16:5

? Int32 or Uint32:10

? Int64 or uint64:19

? Single:7

? Double:15

? Decimal:29

If the exponent is greater than 5 and less than the precision specifier when the number is expressed in scientific notation, the fixed-point notation is used; otherwise, scientific notation is used. If a decimal point is required, and trailing zeros are ignored, the result contains a decimal points. If the precision specifier exists and the number of significant digits in the result exceeds the specified precision, the excess trailing digits are removed by rounding.

There is one exception to the above rule: if the number is Decimal and the precision specifier is omitted. In this case, the fixed point notation is always used and trailing zeros are retained.

When using scientific notation, if the format specifier is "G", the exponent of the result is prefixed with "E", and if the format specifier is "G", the exponent of the result is prefixed with "E".

N or N
Digital
The number is converted to a string in the form "-d,ddd,ddd.ddd ...", where "-" represents a negative sign (if needed), "D" represents a number (0-9), "," represents a thousands separator between numeric groups, "." Represents the decimal point symbol. The actual negative pattern, number group size, thousands separator, and decimal separator are specified by the current NumberFormatInfo object.

The precision specifier indicates the desired number of decimal digits. If the precision specifier is omitted, the default numeric precision given by the current NumberFormatInfo object is used.

P or P
Percentage
The number is converted to a string that represents a percentage, defined by the Numberformatinfo.percentnegativepattern or Numberformatinfo.percentpositivepattern property, The former is used in the case where the number is negative and the latter is used for positive numbers. The converted number is multiplied by 100 to represent a percentage.

The precision specifier indicates the desired number of decimal digits. If the precision specifier is omitted, the default numeric precision given by the current NumberFormatInfo object is used.

R or R
Roundtrip process
This format is supported only for single and Double types. The round-trip specifier guarantees that the numeric value converted to a string is parsed again into the same value. When you use this specifier to format a numeric value, you first test it with the general format: Double uses 15-bit precision, and single uses 7-bit precision. If this value is parsed back to the same value successfully, it is formatted with the general format specifier. However, if this value is not successfully parsed to the same numeric value, it is formatted like this: Double uses 17-bit precision, and single uses 9-bit precision.

Although there can be a precision specifier here, it is ignored. When this specifier is used, the round-trip process takes precedence over precision.

X or X
Hexadecimal number
This format is supported only for integer types. A string that converts a number to a hexadecimal number. The case of the format specifier indicates whether to use uppercase characters or lowercase characters for hexadecimal digits greater than 9. For example, use "X" to produce "ABCDEF" and "X" to produce "ABCDEF".

The precision specifier indicates the minimum number of digits required in the resulting string. If necessary, fill the left side of the number with 0 to produce the number of digits given by the precision specifier.

Any other single character
(unknown specifier)
(The unknown specifier throws a run-Library format exception.) )

Custom Numeric Format Strings

Format specifier name description
0
Zero placeholder
If the formatted value has a number in the format string where "0" appears, this number is copied to the result string. The position of the leftmost "0" before the decimal point and the rightmost "0" after the decimal point determine the total number range that appears in the result string.

The "00" specifier causes the value to be rounded to the nearest digit before the decimal point, where 0 bits are always removed. For example, formatting 34.5 with "00" will get a value of 35.

#
Digit placeholder
If the formatted value has a number in the format string where "#" appears, the number is copied to the result string. Otherwise, no value is stored at this location in the resulting string.

Note that if "0" is not a valid number, this specifier never displays the "0" character, even if "0" is the only number in the string. If "0" is a valid number in the displayed number, the "0" character is displayed.

The "# #" format string allows the value to be rounded to the nearest digit before the decimal point, where 0 is always removed. For example, formatting 34.5 with "# #" will get a value of 35.

.
Decimal point
The first "." In a format string The character determines the position of the decimal separator in the formatted value, and any other "." characters are ignored.

The actual character used as the decimal separator is determined by the NumberDecimalSeparator property that controls the formatted NumberFormatInfo.

,
thousand separators and number scale conversions
The "," character can be used as the thousand separator specifier and the number scale conversion specifier.

thousand separator specifier: If you specify one or more "," characters between two digit placeholders (0 or #) to format the number of integer digits, a group separator character is inserted between each number group in the integer portion of the output.

The NumberGroupSeparator and Numbergroupsizes properties of the current NumberFormatInfo object determine the characters to use as a numeric group separator and the size of each number group. For example, if you use the string "#,#" and the invariant culture to format the number 1000, the output is "1,000".

Numeric scale conversion specifier: If you specify one or more "," characters on the left side of an explicit or implicit decimal point, each occurrence of a numeric scale conversion specifier divides the number that will be formatted by 1000. For example, if you use the string "0," to format the number 1000000000, the output is "100".

You can use the thousands separator specifier and the numeric scale conversion specifier in the same format string. For example, if you use the string "#,0," and the invariant culture to format the number 10000000000, the output is "1,000".

%
Percent placeholder
The presence of a "%" character in a format string causes the number to be multiplied by 100 before formatting. The appropriate symbol is inserted into the number itself in the format string where "%" appears. The percentage character used is determined by the current NumberFormatInfo class.

E0

E+0

E-0

E0

E+0

e-0
Scientific method of notation
If any of the strings "E", "e+", "E", "E", "e+", or "E" appear in the format string and are followed by at least one "0" character, the number is formatted with scientific notation, and "E" or "E" is inserted between the numbers and the exponent. The number of "0" characters following the scientific notation indicator determines the minimum number of digits of the exponential output. The "e+" and "e+" formats indicate that the symbol character (plus or minus) should always precede the exponent. The "E", "E", "E.", or "E" format indicates that the symbol character is placed only in front of the negative exponent.

\
Escape character
In C # and C + +, the backslash character causes the next character in the format string to be interpreted as an escape sequence. It is used in conjunction with a traditional formatted sequence, such as "\ n" (newline).

In some languages, the escape character itself must be followed by an escape character when it is used as text. Otherwise, the compiler will interpret the character as an escape character. Use the string "\ \" to display "\".

Note that this escape character is not supported in Visual Basic, but ControlChars provides the same functionality.

' ABC '

"ABC"
String
Characters that are enclosed in single or double quotation marks are copied into the result string without affecting formatting.

;
Partial separators
“;” Characters are used to separate positive, negative, and 0 parts in a format string.

Other
All other characters
All other characters are copied into the result string and do not affect formatting.

Standard DateTime format string

Format specifier name description
D
Short Date Mode
Represents a custom DateTime format string defined by the current ShortDatePattern property.

For example, the custom format string for the invariant culture is "mm/dd/yyyy".

D
Long Date Mode
Represents a custom DateTime format string defined by the current Longdatepattern property.

For example, the custom format string for the invariant culture is "dddd, dd MMMM yyyy".

F
Full Date/Time mode (short time)
Represents a combination of a long date (D) and a short time (t) pattern, separated by a space.

F
Full Date/Time mode (long time)
Represents a custom DateTime format string defined by the current Fulldatetimepattern property.

For example, the custom format string for the invariant culture is "dddd, dd MMMM yyyy HH:mm:ss".

G
General Date/Time mode (short time)
Represents a combination of a short date (d) and a short time (t) pattern, separated by a space.

G
General Date/Time mode (long time)
Represents a combination of a short date (d) and a long time (T) pattern, separated by a space.

M or M
Month-day mode
Represents a custom DateTime format string defined by the current Monthdaypattern property.

For example, the custom format string for the invariant culture is "MMMM DD".

O
Round-Trip Date/Time mode
Represents a custom DateTime format string that uses a pattern that preserves time zone information. This mode is dedicated to round-trip DateTime formats, including the Kind property in textual form. The parse or ParseExact is then used together with the correct Kind property value to reverse parse the formatted string.

The custom format string is "yyyy '-' mm '-' dd ' T ' HH ': ' mm ': ' Ss.fffffffk '.

The pattern used for this specifier is the defined standard. Therefore, it is always the same regardless of the culture being used or what the provided format provider is.

R or R
RFC1123 mode
Represents a custom DateTime format string defined by the current Rfc1123pattern property. The pattern is a defined standard, and the property is read-only. Therefore, it is always the same regardless of the culture being used or what the provided format provider is.

Define the format string for "ddd, DD MMM yyyy HH ': ' mm ': ' SS ' GMT '".

Formatting does not modify the value of a DateTime object that is being formatted. Therefore, the application must convert the value to Coordinated Universal Time (UTC) before using this format specifier.

S
Sortable date/time mode; ISO 8601 compliant
Represents a custom DateTime format string defined by the current Sortabledatetimepattern property. This pattern is a defined standard, and the property is read-only. Therefore, it is always the same regardless of the culture being used or what the provided format provider is.

The custom format string is "yyyy '-' mm '-' dd ' T ' HH ': ' mm ': ' SS '.

T
Short time mode
Represents a custom DateTime format string defined by the current Shorttimepattern property.

For example, the custom format string for the invariant culture is "hh:mm".

T
Long time mode
Represents a custom DateTime format string defined by the current Longtimepattern property.

For example, the custom format string for the invariant culture is "HH:MM:SS".

U
Universal sortable Date/Time mode
Represents a custom DateTime format string defined by the current Universalsortabledatetimepattern property. This pattern is a defined standard, and the property is read-only. Therefore, it is always the same regardless of the culture being used or what the provided format provider is.

The custom format string is "yyyy '-' mm '-' dd HH ': ' mm ': ' SS ' Z '".

Time zone conversion is not performed when formatting dates and times. Therefore, the application must convert the local date and time to Coordinated Universal Time (UTC) before using this format specifier.

U
Universal sortable Date/Time mode
Represents a custom DateTime format string defined by the current Fulldatetimepattern property.

This mode is the same as the full date/long time (F) pattern. However, formatting will be used in Coordinated Universal Time (UTC), which is equivalent to the DateTime object being formatted.

Y or Y
Month mode
Represents a custom DateTime format string defined by the current Yearmonthpattern property.

For example, the custom format string for the invariant culture is "yyyy MMMM".

Any other single character
(unknown specifier)
An unknown specifier throws a run-time format exception.

Custom DateTime Format Strings

Format specifier description
D
Represents the month date as a number from 1 to 31. The date of one number is set to a format without leading zeros. For more information about using a single format specifier, see Using a single custom format specifier.

Dd
Represents the month date as a number from 01 to 31. The date of one digit is set to a format with leading zeros.

Ddd
Represents the abbreviated name of the day of the week as the name defined in the current System.Globalization.DateTimeFormatInfo.AbbreviatedDayNames property.

DDDD (plus any number of "D" specifiers)
Represents the full name of the day of the week as defined in the current System.Globalization.DateTimeFormatInfo.DayNames property.

F
Represents the most significant bit of the second part.

Note that if the "f" format specifier is used alone and there is no other format specifier, the specifier is considered to be the "F" standard DateTime format specifier (full date/time pattern). For more information about using a single format specifier, see Using a single custom format specifier.

When this format specifier is used with the ParseExact or TryParseExact method, the number of "F" format specifiers indicates the most significant number of bits of the second part to parse.

Ff
Represents the two most significant bits of the second part.

Fff
Represents the three most significant bits of the second part.

Ffff
Represents the four most significant bits of the second part.

Fffff
Represents the five most significant bits of the second part.

Ffffff
Represents the six most significant bits of the second part.

Fffffff
Represents the seven most significant bits of the second part.

F
Represents the most significant bit of the second part. If the bit is zero, no information is displayed. For more information about using a single format specifier, see Using a single custom format specifier.

When this format specifier is used with the ParseExact or TryParseExact method, the number of "F" format specifiers indicates the maximum number of digits of the most significant bit of the second part to parse.

Ff
Represents the two most significant bits of the second part. However, trailing 0 (or two 0-bit) is not displayed.

FFF
Represents the three most significant bits of the second part. However, trailing 0 (or three 0-bit) is not displayed.

FFFF
Represents the four most significant bits of the second part. However, trailing 0 (or four 0-bit) is not displayed.

FFFFF
Represents the five most significant bits of the second part. However, trailing 0 (or five 0-bit) is not displayed.

FFFFFF
Represents the six most significant bits of the second part. However, trailing 0 (or six 0-bit) is not displayed.

FFFFFFF
Represents the seven most significant bits of the second part. However, trailing 0 (or seven 0-bit) is not displayed.

G or GG (plus any number of "G" specifiers)
Represents a period or era (for example, A.D.). If the date to be formatted does not have an associated period or era string, the descriptor is ignored. For more information about using a single format specifier, see Using a single custom format specifier.

H
The hour is expressed as a number from 1 to 12, that is, the hour is represented by a 12-hour system, and the whole hour is counted from midnight or noon. Therefore, a specific number of hours after midnight cannot be distinguished from the same number of hours after noon. The number of hours is not rounded, and the number of hours for one digit is set to a format without leading zeros. For example, given a time of 5:43, this format specifier displays "5". For more information about using a single format specifier, see Using a single custom format specifier.

HH, hh (plus any number of "H" specifiers)
The hour is expressed as a number from 01 to 12, that is, the hour is represented by a 12-hour system, and the whole hour is counted from midnight or noon. Therefore, a specific number of hours after midnight cannot be distinguished from the same number of hours after noon. The number of hours is not rounded, and the number of hours for one digit is formatted with a leading zero. For example, given a time of 5:43, this format specifier displays "05".

H
The hour is expressed as a number from 0 to 23, that is, the hour is represented by a zero-based 24-hour system, and the hours are counted from midnight onwards. The number of hours of one digit is set to a format without leading zeros.

HH, hh (plus any number of "H" specifiers)
The hour is expressed as a number from 00 to 23, that is, the hour is represented by a zero-based 24-hour system, and the hours are counted from midnight onwards. The number of hours of one digit is set to a format with leading zeros.

K
Represents a different value for the Datetime.kind property, which is "Local", "UTC", or "Unspecified". This specifier loops the Kind value and preserves the time zone in textual form. If the Kind value is "local", this specifier is equivalent to the "zzz" specifier, which is used to display the local time offset, such as " -07:00". For the "UTC" Type value, the specifier displays the character "Z" to represent the UTC date. For the "Unspecified" type value, this specifier is equivalent to "" (Nothing).

M
The minute is expressed as a number from 0 to 59. Minutes represents the number of full minutes elapsed since the previous hour. The number of minutes for one digit is set to a format without leading zeros. For more information about using a single format specifier, see Using a single custom format specifier.

MM, mm (plus any number of "M" specifiers)
The minute is expressed as a number from 00 to 59. Minutes represents the number of full minutes elapsed since the previous hour. The number of minutes for one digit is set to a format with leading zeros.

M
The month is represented as a number from 1 to 12. The month of one digit is set to a format without leading zeros. For more information about using a single format specifier, see Using a single custom format specifier.

Mm
The month is represented as a number from 01 to 12. The month of one digit is set to a format with leading zeros.

MMM
Represents the abbreviated name of the month as the name defined in the current System.Globalization.DateTimeFormatInfo.AbbreviatedMonthNames property.

MMMM
Represents the full name of the month as defined in the current System.Globalization.DateTimeFormatInfo.MonthNames property.

S
Represents the second as a number from 0 to 59. Seconds represents the number of seconds elapsed since the first minute. The number of seconds for one digit is set to a format without leading zeros. For more information about using a single format specifier, see Using a single custom format specifier.

SS, SS (plus any number of "s" specifiers)
Represents the second as a number from 00 to 59. Seconds represents the number of seconds elapsed since the first minute. The number of seconds for one digit is set to a format with leading zeros.

T
Represents the current System.Globalization.DateTimeFormatInfo.AMDesignator or System.Globalization.DateTimeFormatInfo.PMDesignator The first character of the A.M./P.M. indicator as defined in the properties. If the number of hours in the time being formatted is less than 12, the A.M. indicator is used, otherwise the p.m. indicator is used. For more information about using a single format specifier, see Using a single custom format specifier.

TT, TT (plus any number of "T" specifiers)
Represents the A.M./P.M. Indicator as the current System.Globalization.DateTimeFormatInfo.AMDesignator or The content defined in the System.Globalization.DateTimeFormatInfo.PMDesignator property. If the number of hours in the time being formatted is less than 12, the A.M. indicator is used, otherwise the p.m. indicator is used.

Y
Represents the year as a maximum of two digits. If the year is more than two digits, only the two-digit low number is shown in the result. If the year is less than two digits, the number is set to a format without leading zeros. For more information about using a single format specifier, see Using a single custom format specifier.

Yy
Represents the year as a two-digit number. If the year is more than two digits, only the two-digit low number is shown in the result. If the year is less than two digits, the number is populated with leading 0 to reach the two-digit number.

yyy
Represents the year as a three-digit number. If the year is more than three digits, only the three-bit low number is displayed in the results. If the year is less than three digits, the number is populated with leading 0 to reach the three-digit number.

Note that for a Thai Buddhist calendar with a year that can be five digits, this format specifier displays all five digits.

yyyy
Represents the year as a four-digit number. If the year is more than four digits, only the four-digit low number is displayed in the result. If the year is less than four digits, the number is populated with leading 0 to reach the four-digit number.

Note that for a Thai Buddhist calendar with a year that can be five digits, this format specifier renders all five digits.

YYYYY (plus any number of "Y" specifiers)
Represents the year as a five-digit number. If the year is more than five digits, only the five-digit low number is displayed in the result. If the year is less than five digits, the number is populated with leading 0 to reach the five-digit number.

If an additional "Y" specifier is present, the number is populated with a leading 0 of the desired number to reach the number of "Y" descriptors.

Z
Represents the signed time zone offset for the system when the interval GMT (GMT) is measured in hours. For example, a computer in the Pacific Standard Time zone has an offset of "-8".

The offset is always displayed with a leading symbol. The plus sign (+) indicates that the number of hours is earlier than GMT, and the minus sign (-) indicates that the hours are later than GMT. The offset range is –12 to +13. The offset of one number is set to a format without leading zeros. The offset is influenced by the summer time system. For more information about using a single format specifier, see Using a single custom format specifier.

Zz
Represents the signed time zone offset for the system when the interval GMT (GMT) is measured in hours. For example, a computer in the Pacific Standard Time zone has an offset of "-08".

The offset is always displayed with a leading symbol. The plus sign (+) indicates that the number of hours is earlier than GMT, and the minus sign (-) indicates that the hours are later than GMT. The offset range is –12 to +13. The offset of one number is set to a format with leading zeros. The offset is influenced by the summer time system.

ZZZ, zzz (plus any number of "Z" specifiers)
Represents the signed time zone offset, measured in hours and minutes, when the system is spaced GMT (GMT). For example, a computer in the Pacific Standard Time zone has an offset of " -08:00".

The offset is always displayed with a leading symbol. The plus sign (+) indicates that the number of hours is earlier than GMT, and the minus sign (-) indicates that the hours are later than GMT. The offset range is –12 to +13. The offset of one number is set to a format with leading zeros. The offset is influenced by the summer time system.

:
The time separator defined in the current System.Globalization.DateTimeFormatInfo.TimeSeparator property to distinguish between hours, minutes, and seconds.

/
The date separator, defined in the current System.Globalization.DateTimeFormatInfo.DateSeparator property, that distinguishes the year, month, and day.


Quoted string (quotation marks). Displays the text value of any string between two quotation marks ("). Use the escape character (\) before each quotation mark.


Quoted string (apostrophe). Displays the text value of any string between the two apostrophe (') characters.

%c
When a custom DateTime format string contains only the custom format specifier "C", the result associated with the custom format specifier is represented. In other words, to use the custom format specifier "D", "F", "F", "H", "M", "s", "T", "Y", "Z", "H" or "M", please specify "%d", "%f", "%f", "%h", "%m", "%s", "%t", "%y", "%z" , "%H", or "%M". For more information about using a single format specifier, see Using a single custom format specifier.

\c
The escape character. When the character "C" is preceded by an escape character (\), the character is displayed as text. To insert the backslash character itself into a result string, use two escape characters ("\ \").

Any other character
All other characters are copied into the result string and do not affect formatting.

Enumeration Format Strings

Format string Result
G or G
Displays an enumerated item as a string value, if possible, otherwise displays the integer value of the current instance. If the Flags property is set in the enumeration definition, concatenates the string values of each valid item and separates the values with commas. If the Flags property is not set, the invalid value is displayed as a numeric entry.

F or F
Displays the enumeration items as string values, if possible. If the value can be fully displayed as the sum of the enumerated items (even if the Flags property is not provided), concatenate the string value of each valid item and separate the values with commas. If the value cannot be determined entirely by an enumeration item, the value is formatted as an integer value.

D or D
Displays an enumerated item as an integer value in the shortest possible representation.

X or X
Displays an enumeration entry as a hexadecimal value. The value is expressed as required with a leading zero to ensure that the value is at least eight bits long.

String. Usage of format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.