How can I split the string @"Hello"
to either:
'H'
, 'e'
, 'l'
, 'l'
, 'o'
or:
@[@"H", @"e", @"l", @"l", @"o"]
If you're satisfied with a C array of char
s, try:
const char *array = [@"Hello" UTF8String];
If you need an NSArray, try:
NSMutableArray *array = [NSMutableArray array];
NSString *str = @"Hello";
for (int i = 0; i < [str length]; i++) {
NSString *ch = [str substringWithRange:NSMakeRange(i, 1)];
[array addObject:ch];
}
And array
will contain each character as an element of it.