Skip to content

Instantly share code, notes, and snippets.

@yanks
Created May 15, 2011 18:43
Show Gist options
  • Save yanks/973419 to your computer and use it in GitHub Desktop.
Save yanks/973419 to your computer and use it in GitHub Desktop.
NSString* truncateString(NSString* input)
{
NSCountedSet* set = [[NSCountedSet alloc] init];
for( int i = 0; i < [input length]; i++ ){
[set addObject:[NSString stringWithFormat:@"%c", [input characterAtIndex:i]]];
}
NSMutableString* result = [[NSMutableString alloc] init];
for( NSString* key in set ){
[result appendString:key];
if( [set countForObject:key] > 1 ){
[result appendString:key];
}
}
[set release];
return [result autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment