File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ #import < Foundation/Foundation.h>
2+
3+ // Source:
4+ // https://stackoverflow.com/questions/260945/create-nsstring-by-repeating-another-string-a-given-number-of-times
5+ @interface NSString (Baklava)
6+ - (NSString *) repeatString : (NSUInteger ) times ;
7+ @end
8+
9+ @implementation NSString (Baklava)
10+ - (NSString *) repeatString : (NSUInteger ) times {
11+ return [
12+ @" "
13+ stringByPaddingToLength: [self length ] * times
14+ withString: self startingAtIndex: 0
15+ ];
16+ }
17+ @end
18+
19+ int main (int argc, const char * argv[]) {
20+ NSAutoreleasePool *pool =[[NSAutoreleasePool alloc ] init ];
21+
22+ int i;
23+ for (i = -10 ; i <= 10 ; i++) {
24+ int numSpaces = abs (i);
25+ int numStars = 21 - 2 * numSpaces;
26+ printf (
27+ " %s%s \n " ,
28+ [[@" " repeatString: numSpaces] UTF8String ],
29+ [[@" *" repeatString: numStars] UTF8String ]
30+ );
31+ }
32+
33+ [pool drain ];
34+ return 0 ;
35+ }
You can’t perform that action at this time.
0 commit comments