Club 15CC

Strings ~ 15CC Code

Task Code
iOS Convert a Float to a Price in a Specific Locale with NSNumberFormatter »
float newPrice = 1234.56;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-GB"];
myLabel.text = [formatter stringFromNumber:@(newPrice)];
iOS Get a String of a Number Rounded to a Decimal Place in Cocoa/iOS »
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
nf.maximumFractionDigits = 1;
aLabel.text = [nf stringFromNumber:@(sender.value)];
bash Search and Replace Filenames in Bash – 2 ways »
# Find files prefixed with SW and replace with IN
# Adapted from  http://stackoverflow.com/questions/9393607/find-and-replace-filename-recursively-in-a-directory

# No pipes (see the SO post for explanation)
find . -name 'SW*' -type f -exec bash -c 'mv "$1" "${1/SW/IN/}"' -- {} \;

# Looping
find -name 'SW*' | while read file; do mv "$file" "${file/SW/IN}"; done
Linux Search and replace on files from the BASH command line… » -i is for writing the result back to the file. -e...
# All files...
sed -ie "s/IM/MC/g" *

# More flexibility
find ./ -name "*.m" | xargs sed -ie "s/IM/MC/g" *
iOS Implode / concat NSArray elements into a string »
[self.notesArray componentsJoinedByString:@" "];
iOS Concatenate multiple path components safely »
NSString *path1 = @"/Volumes/Path/to.something/";
NSString *path2 = @"/special";
NSString *filename = @"afile.txt";

NSString *all = [[path1 stringByAppendingPathComponent:path2] stringByAppendingPathComponent:filename];
iOS Get the folder part of a full path filename »
NSString *file = @"/Volumes/Path/to.something/my/file.bundle";
NSString *folder = [file stringByDeletingLastPathComponent];