Split an NSString into an array in Objective-C

前端 未结 4 679
傲寒
傲寒 2021-02-05 14:23

How can I split the string @\"Hello\" to either:

  • a C array of \'H\', \'e\', \'l\', \'l\', \'
4条回答
  •  忘掉有多难
    2021-02-05 14:25

    Try this :

    - (void) testCode
    {
        NSString *tempDigit = @"12345abcd" ;
        NSMutableArray *tempArray = [NSMutableArray array];
        [tempDigit enumerateSubstringsInRange:[tempDigit rangeOfString:tempDigit]
                                      options:NSStringEnumerationByComposedCharacterSequences
                                   usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                [tempArray addObject:substring] ;
            }] ;
    
        NSLog(@"tempArray = %@" , tempArray);
    }
    

提交回复
热议问题