Truncate a string and add ellipsis at the end in Objective-c

ios, iphone, objective-c

Solution

NSString *origString = @"A very long string blah blah blah";
const int clipLength = 18;
if([origString length]>clipLength)
{
    origString = [NSString stringWithFormat:@"%@...",[origString substringToIndex:clipLength]];
}

Problem

How to truncate a string in Objective-C and then add the ellipsis at the end?

Original source