PDA

View Full Version : Split NSString into array of characters?




tsornin
Sep 23, 2008, 03:52 PM
Is there a way to split a string into an array of individual characters? I've tried this but it doesn't seem to work:

NSString *foo = @"The quick brown fox";
NSArray *chars = [foo componentsSeparatedByString:@""];

But then the length of chars is 1, and chars[0] contains the entire string rather than just "T".

I must be missing something obvious...



robbieduncan
Sep 23, 2008, 03:53 PM
You can turn them into a C array of unicode characters with getCharacters: (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/getCharacters:).