Darkleo’s Blog
Ein Schatz, der seinen Besitzer überallhin begleitet.

string.Format(”{0,X}”,X)

August 6th, 2009 by darkleo

Ich habe ziemlich viel Zeit damit verbracht, einen String mit Leerzeichen zu belegen,

string.Format("{0:D5}",223);  // 000223

doch ich wollte [ ][ ][ ]223 abbilden, die Lösung ist ziemlich Einfach, wenn man es kennt.

string.Format("{0,5}",223);  // [ ][ ][ ]223

was auch funktioniert

string.Format("{0,-5}",223);  // 223[ ][ ][ ]

Weitere Formatierungen: http://alexonasp.net/samples/stringformatting/

Posted in .NET, C#

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.