Shortcuts in Objective-C to concatenate NSStrings

前端 未结 30 2653
伪装坚强ぢ
伪装坚强ぢ 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 08:01

    I keep returning to this post and always end up sorting through the answers to find this simple solution that works with as many variables as needed:

    [NSString stringWithFormat:@"%@/%@/%@", three, two, one];
    

    For example:

    NSString *urlForHttpGet = [NSString stringWithFormat:@"http://example.com/login/username/%@/userid/%i", userName, userId];
    

提交回复
热议问题