0

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

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.