aligning hexadecimal output
-
how can i tell C# to fill remaining space with '0'? when writing:
string.Format("0x{0,4:X}",256);
i get
0x 100
but i want
0x0100
the msdn-documentaition just says "...is padded with spaces" - no word on changing the fill-character. is this possible at all? :confused: :wq
-
how can i tell C# to fill remaining space with '0'? when writing:
string.Format("0x{0,4:X}",256);
i get
0x 100
but i want
0x0100
the msdn-documentaition just says "...is padded with spaces" - no word on changing the fill-character. is this possible at all? :confused: :wq
String.PadLeft Method Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length.
public string PadLeft(int, char);
:) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D -
how can i tell C# to fill remaining space with '0'? when writing:
string.Format("0x{0,4:X}",256);
i get
0x 100
but i want
0x0100
the msdn-documentaition just says "...is padded with spaces" - no word on changing the fill-character. is this possible at all? :confused: :wq
-
String.PadLeft Method Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length.
public string PadLeft(int, char);
:) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D -
current workaround (input is a Int16, so 4 chars are always enough)
Int16 id = // set somewhere before
string.Format("0x{0}{1}{2}{3:X}",(id<4096)?"0":"",(id<256)?"0":"",(id<16)?"0":"",id);but thats kind of X| :wq
int f = 256; string s = f.ToString("0000");
And I swallow a small raisin.