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

后端 未结 7 1511
名媛妹妹
名媛妹妹 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:46

    I would not have given the answer of such general question. There are many answers of same type question have already given. First find the answer of your question from existing question.

    NSString* myURLString = [NSString stringWithFormat:@"http://www.websitehere.com/index.php?s=%@", search.text];
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-31 10:48

    You can use stringByAppendingString:

     stringURL = [@"http://www.websitehere.com/index.php?s=" 
                          stringByAppendingString:search.text];
    
    0 讨论(0)
  • 2020-12-31 10:50
    NSString* combinedString = [stringUrl stringByAppendingString: search.text];
    
    0 讨论(0)
  • 2020-12-31 10:50

    If you want to have some control about the format of the parameter you should assemble your URL string with

    [NSString stringWithFormat:@"http://www.websitehere.com/index.php?s=%@", search.text]
    

    This solution is charming because you can append almost anything which can be inserted into a printf-style format.

    0 讨论(0)
  • 2020-12-31 10:54

    NSString * combined = [stringURL stringByAppendingString:stringSearch];

    0 讨论(0)
提交回复
热议问题