Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wrayal

macrumors newbie
Original poster
Aug 23, 2008
9
0
Hi,

I need to output some numbers to an NSTextField. The numbers are unsigned short ints, and I need to output them in the form ****h in hexadecimal, where number is zero-padded at the beginning if it is <0x1000. Currently, I'm using:

[AFbox setStringValue:[NSString stringWithFormat:mad:"%4Xh", [cpu AF]]];

But I really can't see a good way of zero-padding the string...can someone point me in the right direction? ([cpu AF returns the unsigned short ints).

Many thanks,

Wrayal

[edit: I have tried stringByPaddingToLength:withString:startingAtIndex:, but this will only pad at the end as far as I can tell]
 

harry65

macrumors member
Aug 26, 2008
36
0
Try

Code:
[AFbox setStringValue:[NSString stringWithFormat:@"%04Xh", [cpu AF]]];

The '0' before the '4' specifies what you want your padding character to be.

Edit:

I actually made it sound like you can choose any padding character you want... I don't think that's the case. I do know that putting a '0' here will pad with 0's
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.