Created
March 4, 2013 04:14
-
-
Save rustle/5079872 to your computer and use it in GitHub Desktop.
Example of prefixing a list with a leading character. In this case, adding a • to the front of each line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *someText = ...; | |
NSMutableString *someLines = [NSMutableString new]; | |
[someText enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) { | |
// Make sure the line isn't just whitespace | |
NSMutableString *mutableLine = [line mutableCopy]; | |
CFStringTrimWhitespace((__bridge CFMutableStringRef)mutableLine); | |
if ([mutableLine length]) | |
{ | |
[someLines appendFormat:@" • %@\n", line]; | |
} | |
}]; | |
if ([someLines length]) | |
{ | |
[someLines deleteCharactersInRange:NSMakeRange([someLines length] - 1, 1)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment