1

i found this Is it possible to use format strings to align NSStrings like numbers can be?

I have a similar task but the opposite format.

   TOTAL:      2
SUBTOTAL:   6.00
     TAX:     0%
    CASH:  12.00

my code is this

NSString* item [NSString stringWithFormat:@"%-10s %@", @"TOTAL",@"2"];

Yet outcome is this

TOTAL:   2
SUBTOTAL:  6.00

UPDATE

I got it to work with this code.

NSString* item [NSString stringWithFormat:@"%12s %7s", [total UTF8String],[amount UTF8String]];

UPDATE QUESTION

What if the text is too long?

THIS TEXT IS TOO LONG

I want it to be

THIS TEXT
IS TOO LONG
Community
  • 1
  • 1
n0minal
  • 3,195
  • 9
  • 46
  • 71

0 Answers0