views:

86

answers:

2

Hi,

How to Format a Number to a Hexicadecimal with a Prefix '0x'?

Such as:

int space = 32;
MessageBox.Show(space.ToString("'0x'X4")); // Output 0xX4 instead of 0x0020

I followed this link: Custom Numeric Format Strings http://msdn.microsoft.com/en-us/library/0c899ak8.aspx Literal string delimiter: Indicates that the enclosed characters should be copied to the result string unchanged. But it does not work for 'X4' (it does work for '#'), kind of weird.

I'm using it in a DataGridView.DefaultCellStyle.Format, so I cannot use:

"0x{0:X4}", space

Thanks. Peter

A: 

Does this help?

http://msdn.microsoft.com/en-us/library/fht0f5be.aspx

Matthew
As the OP has explicitly stated, it doesn’t.
Konrad Rudolph
As I said, I'm using it in a DataGridView.DefaultCellStyle.Format. So I cannot use {0} format.
Peter Lee
A: 

try checking here: http://stackoverflow.com/questions/2715710/creating-a-custom-format-string-in-a-datagridview

Anurag
Hi Anurag, thanks for your link. but I think that solution sounds to me a workaround-like solution, though it's working. I think we should be allowed directly set the format in Design-time ('#' works, but 'X' not)
Peter Lee