TOP KEK
TOP KEK

Reputation: 2651

Shortest code to create a string with specified lengh

What is the shortest way to create a string with spaces and desired length in Objective-C?

I can do it using for cycle, but it's several lines of code.

Upvotes: 0

Views: 84

Answers (2)

Warif Akhand Rishi
Warif Akhand Rishi

Reputation: 24248

Returns first six characters

NSString *fullName = @"Warif Akhand Rishi";
NSString *subString = [fullName substringToIndex:6];

Upvotes: 2

AndersK
AndersK

Reputation: 36082

Have you looked at stringWithFormat ?

[NSMutableString stringWithFormat:@"%20d", 42];

Upvotes: 0

Related Questions