【C#】空白埋め、0埋め、指定文字埋めする方法
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
int value = 123; | |
Console.WriteLine("{0,5}", value); // 左空白埋め | |
Console.WriteLine("{0,-5}", value); // 右空白埋め | |
Console.WriteLine("{0:D5}", value); // 0埋め | |
Console.WriteLine(value.ToString().PadLeft(5, '*')); // 左指定文字埋め | |
Console.WriteLine(value.ToString().PadRight(5, '*')); // 右指定文字埋め | |
// 出力: | |
// 123 | |
// 123 | |
// 00123 | |
// **123 | |
// 123** |
コメント
コメントを投稿