objective-ciosxcodecocoa-touch

NSLog, how can I produce a fixed width output for different size fields?


I want to produce an output of data which will line up, but the fields can have different widths.

For example, one field is an INT, it can be from 1 character to 3 characters in length.

Is there a way to get NSLog to pad fields ?


Solution

  • for(int i=0; i<2000; i+=50) {
        NSLog(@"%4d", i);
    }
    

    Where 4 is alignment.