Created
November 14, 2013 03:00
-
-
Save yoshikazuendo/7460602 to your computer and use it in GitHub Desktop.
標準の数値書式指定文字列とかカスタム書式とか。ToString(String)メソッドなどで、数値のフォーマットを指定して文字列で表現することができます。たまにしか使わないから忘れちゃうんですよね。結構色々あっておもしろい。http://msdn.microsoft.com/ja-jp/library/dwhawy9k(v=vs.110).aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://msdn.microsoft.com/ja-jp/library/8kb3ddd4(v=vs.110).aspx | |
// 日付型を.ToStringで書式指定できるけど、年の下一桁はシンプルにできない。ので、Substringを組み合わせる。 | |
Console.WriteLine(DateTime.Now.ToString("yy").Substring(1, 1)); // 2013の"3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str1 = 1234.ToString("D6"); // 10進数表記 "001234" | |
var str2 = 255.ToString("X3"); // 16進数表記 "0FF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment