Skip to content

Instantly share code, notes, and snippets.

Created Jan 19, 2015
What would you like to do?
NSString routine that generates a fix length brief
static NSInteger mYStringlength = 60;
- (NSString *)brief:(NSString *)text
NSRange stringRange = {0, MIN([text length], mYStringlength)};
stringRange = [text rangeOfComposedCharacterSequencesForRange:stringRange];
NSString *shortBrief = [text substringWithRange:stringRange];
NSString *firstLine =[[self.text componentsSeparatedByString: @"\n"] objectAtIndex:0];
// if firstLine is shorter than our expected length
if (firstLine.length < mYStringlength) {
return firstLine;
// truncate desc by length if text is too long
if (mYStringlength < desc.length) {
return [NSString stringWithFormat:@"%@...", shortBrief];
} else {
return text;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment