How to iterate through the characters of an NSString

后端 未结 3 919
孤街浪徒
孤街浪徒 2021-01-11 16:04
NSString *myStrings = @\"abcdefghijklmnopqrstuvwxyz\";

How could I iterate each of the letters (a, b, c, d, e, etc..) in an Objective-C for

3条回答
  •  礼貌的吻别
    2021-01-11 16:30

    Enumerate substrings of NSString characters with a block

    NSString *characters = @"abcdefghijklmnopqrstuvwxyz";
    [characters enumerateSubstringsInRange:NSMakeRange(0, characters.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
    
         NSLog(@"substring: %@ substringRange: %@, enclosingRange %@", substring, NSStringFromRange(substringRange), NSStringFromRange(enclosingRange));
    
     }];
    

提交回复
热议问题