Reputation: 7150
I want to generate a 4 character hex number.
To generate a hex number you can use
string.format("{0:X}", number)
and to generate a 4 char string you can use
string.format("{0:0000}", number)
Is there any way to combine them?
Upvotes: 2
Views: 2515
Reputation: 1499760
Have you tried:
string hex = string.Format("{0:X4}", number);
? Alternatively, if you don't need it to be part of a composite pattern, it's simpler to write:
string hex = number.ToString("X4");
Upvotes: 4
Reputation: 391286
I'm assuming you mean: 4-digit hexadecimal number.
If so, then yes:
string.Format("{0:X4}", number)
should do the trick.
Upvotes: 5