.net - Number format string to show only right 2 digits -


I know that I can use substrings or other methods, but I'm just curious if there is some place? To return it below "09"

  string.format ({0:?}, 2009);  

BTW, I came across a good cheat sheet while trying to figure out ...

If you have a legitimate need to further refine, you can always create your own custom format provider:

Whatever pattern you want to your string , Can form it properly, and incorporate the functionality of the reuse properly.

Here's an example:

  class program {static wide main (string [] arg) {var date = "2009"; Console Type (string.format (new customform provider (), "{0: YY}", date)); Console.ReadKey (); } Public class CustomFormatProvider: IFormatProvider, ICustomFormatter {public object GetFormat (type formatType) {if (formatType == type (ICustomFormatter)) this back; And tap return; } Public string format (string FMT, object AGR, IFermatProvider format provider) {string year = arg.ToString (); String result = string Empty; Fmt = fmt.Trim (). ToUpper (); If (fmt.Equals ("YY")) return year. Shuttle (2, 2); And if (FMT. ("YYYY")) return year; And then click on the new format xDestation (string.format ("{0} is not a valid format string.", FMT);}}}  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -