Tuesday, August 31, 2010

How to get composite name from ABRecordRef

ABRecordRef *person = (ABRecordRef *)[allPeople objectAtIndex:i];
// Display Name
NSString *displayName = (NSString *)ABRecordCopyCompositeName(person);

Trim String in Object C

This is how to trim a string and remove whitespace and newlines:

NSString *trimmedString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];


For other character sets, refer to
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSCharacterSet_Class/Reference/Reference.html#//apple_ref/doc/uid/20000157-SW5.

Sunday, August 15, 2010

how to rename in Mac OS

This is a command based solution. Works for Leopard, Snow Leopard or anything with ZSH

duck% zsh
duck% autoload zmv
duck% zmv '*.jpg' '$f:s/2_/518_/'