How to combine two strings in Objective-C for an iPhone app

后端 未结 7 1666
名媛妹妹
名媛妹妹 2020-12-31 10:21

How can I combine \"stringURL\" and \"stringSearch\" together?

- (IBAction)search:(id)sender;{
stringURL = @\"http://www.websitehere.com/index.php?s=\";
stri         


        
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 10:48

    Instead of stringByAppendingString:, you could also use

    NSString *combined = [NSString stringWithFormat: @"%@%@", 
                                     stringURL, stringSearch];
    

    This is especially interesting/convenient if you have more than one string to append. Otherwise, the stringbyAppendingString: method is probably the better choice.

提交回复
热议问题