Shortcuts in Objective-C to concatenate NSStrings

前端 未结 30 2905
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 07:03

Are there any shortcuts to (stringByAppendingString:) string concatenation in Objective-C, or shortcuts for working with NSString in general?

30条回答
  •  不要未来只要你来
    2020-11-22 07:51

    Let's imagine that u don't know how many strings there.

    NSMutableArray *arrForStrings = [[NSMutableArray alloc] init];
    for (int i=0; i<[allMyStrings count]; i++) {
        NSString *str = [allMyStrings objectAtIndex:i];
        [arrForStrings addObject:str];
    }
    NSString *readyString = [[arrForStrings mutableCopy] componentsJoinedByString:@", "];
    

提交回复
热议问题