Repeat a string: Difference between revisions
Content added Content deleted
(Add Objective-C example.) |
m (→{{header|Objective-C}}: Updated lang tag from c to objc.) |
||
Line 441: | Line 441: | ||
We will extend NSString, the de facto Objective-C string class in environments that are either compatible with or descend directly from the OPENSTEP specification, such as GNUstep and Mac OS X, respectively, with a method that accomplishes the described task. |
We will extend NSString, the de facto Objective-C string class in environments that are either compatible with or descend directly from the OPENSTEP specification, such as GNUstep and Mac OS X, respectively, with a method that accomplishes the described task. |
||
<lang |
<lang objc> |
||
@interface NSString (RosettaCodeAddition) |
@interface NSString (RosettaCodeAddition) |
||
- (NSString *) repeatStringByNumberOfTimes: (NSUInteger) times; |
- (NSString *) repeatStringByNumberOfTimes: (NSUInteger) times; |
||
Line 467: | Line 467: | ||
Now, let's put it to use: |
Now, let's put it to use: |
||
<lang |
<lang objc> |
||
// Instantiate an NSString by sending an NSString literal our new |
// Instantiate an NSString by sending an NSString literal our new |
||
// -repeatByNumberOfTimes: selector. |
// -repeatByNumberOfTimes: selector. |
||
Line 485: | Line 485: | ||
// implied by its name. |
// implied by its name. |
||
</lang> |
</lang> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
<lang ocaml>let string_repeat s n = |
<lang ocaml>let string_repeat s n = |