views:

30

answers:

1

Is there a way to use Int32.ToString("<some string format specifier>") with using more than 1 specifiers? Specifically, I want to format an int in Hexadecimal but force the string to be 8-bit long, by adding 0's in the empty spots. For example, I want to parse the number 1234 in decimal to the string "000004D2".

The way I wanted to do this was by combining the specifiers "X" and "00000000", but I can't seem to find any examples of combining specifiers together. Do I need to create my own FormatProvider?

I need to do this because I am writing a viewer which displays an array of bytes which supports different packages and formats. For example, display the array as an array of 4-bytes integers in hexadecimal, or 2-bytes integers in signed display. Much like the Memory viewer in VS

+4  A: 

For that specific example, you can just use "X8" as your format specifier. I don't know about the more general case - but if you have any other specific requirements, it's probably worth asking about those separately.

Jon Skeet
good enough for my needs, thanks
eladidan