How can I combine "stringURL" and "stringSearch" together?
- (IBAction)search:(id)sender;{
stringURL = @"http://www.websitehere.com/index.php?s=";
stringSearch = search.text;
/* Something such as:
stringURL_ = stringURL + stringSearch */
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:stringURL_]]];
}
NSString* combinedString = [stringUrl stringByAppendingString: search.text];
Philippe gave a good example.
You can also use plain stringWithFormat
: method.
NSString *combined = [NSString stringWithFormat:@"%@%@", stringURL, stringSearch];
This way you can manipulate string even more by putting somethig inbetween the strings like:
NSString *combined = [NSString stringWithFormat:@"%@/someMethod.php?%@", stringURL, stringSearch];
NSString * combined = [stringURL stringByAppendingString:stringSearch];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With