// gcc -o strings stringstuff.m -framework Foundation // ./strings #import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString *s = [[NSString alloc] initWithString:@"v\nx y;z"]; NSArray *a = [s componentsSeparatedByString:@"\n"]; NSLog(@"a = %@", [a description]); NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:@"\n ;"]; a = [s componentsSeparatedByCharactersInSet:cs]; NSLog(@"a = %@", [a description]);
NSString *s2 = [[NSString alloc] initWithString:@" x y z "]; cs = [NSCharacterSet characterSetWithCharactersInString:@" "]; NSString *s3 = [s2 stringByTrimmingCharactersInSet:cs]; NSLog(@"s3 = %@, length %u", [s3 description], [s3 length]);
[s release]; [s2 release]; [pool drain]; return 0; } |