"%3d" ? (space padding)
"%-3d" ? (left alignment)
"%+3d" ? (adding +/- sign)
"% 3d" ? (adding a space in case of positive vaklue)
(E.g - for zero padding - "%03d" is {0:d3}, but how do I do space
padding - "%3d"? )
I'll appreciate it if you can direct me to the relevant link.
Thanks!
Udi
If you look up "formatting strings" on MSDN, you'll find the "general"
rules for formatting, which includes alignment. So for the example you
gave, you need {0,3:d} for right alignment, and {0,-3:d} for left
alignment. You can also mix and match: {0,3:d2} will give " 05" for
instance.
Jon
How do I do it in c#?
Thanks again for your time!
Udi.
Well, it's the {index,alignment:formatString} notation - the d2 is the
formatString part, and the 3 is the alignment.
> Is there any equivalent for the "u" format specifier?
> What if I have a 32 bit value that want to control the way it is
> printed with the help of the format specifier just like in printf?
> E.g. -
> int i = -1;
> printf("%u", i);
>
> How do I do it in c#?
Do you mean you want to treat a signed integer as an unsigned integer?
It's not clear to me (not having done any C for a while) what you're
trying to do.
Jon
say I have
int i = -1;
but I would like to print it as unsigned, meaning - in this case I'd
like WriteLine() to print the value of MAX_INT.
Is there a way to do it through the format specifiers? I.e. forcing the
value to be printed as unsigned?
Thanks!
Not that I know of, but why don't you just cast it to an unsigned int
in the first place?
Console.WriteLine ("{0:d}", (uint)i);
Jon