Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString stringWithFormat question

I am trying to build a small table using NSString. I cannot seem to format the strings properly.

Here is what I have

[NSString stringWithFormat:@"%8@: %.6f",e,v]

where e is an NSString from somewhere else, and v is a float.

What I want is output something like this:

Grapes:       20.3
Pomegranates:  2.5
Oranges:      15.1

What I get is

Grapes:20.3
Pomegranates:2.5
Oranges:15.1

How can I fix my format to do something like this?

like image 889
John Smith Avatar asked Dec 29 '22 19:12

John Smith


1 Answers

you could try using - stringByPaddingToLength:withString:startingAtIndex:

like image 64
Jonathan Lund Avatar answered Jan 05 '23 00:01

Jonathan Lund