Shortcuts in Objective-C to concatenate NSStrings

前端 未结 30 2904
伪装坚强ぢ
伪装坚强ぢ 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:05

    Create a method:

    - (NSString *)strCat: (NSString *)one: (NSString *)two
    {
        NSString *myString;
        myString = [NSString stringWithFormat:@"%@%@", one , two];
        return myString;
    }
    

    Then, in whatever function you need it in, set your string or text field or whatever to the return value of this function.

    Or, to make a shortcut, convert the NSString into a C++ string and use the '+' there.

提交回复
热议问题