Slide 21
Slide 21 text
Chop chop
#import
void Output(NSString *s) {
[s writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:nil];
}
int main(int argc, char *argv[])
{
NSString *s = @" is chinese";
Output(s); Output([NSString stringWithFormat:@" (len %lu)\n", s.length]);
NSLog(@"%@", s);
NSString *sub = [s substringWithRange:NSMakeRange(1,4)];
Output(sub); Output([NSString stringWithFormat:@" (len %lu)\n", sub.length]);
NSLog(@"%@", sub);
}
$ clang -framework Cocoa test.m -o test && ./test
is chinese (len 15)
2013-02-02 18:47:47.342 test[42044:707] is chinese
(len 4)
$
The substring doesn’t get printed out at all (!)