如何在Objective-C中为iPhone应用程序组合两个字符串 [英] How to combine two strings in Objective-C for an iPhone app

查看:58
本文介绍了如何在Objective-C中为iPhone应用程序组合两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将stringURL和stringSearch组合在一起?

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_]]];
}


推荐答案

Philippe举了一个很好的例子。

Philippe gave a good example.

你也可以使用普通的 stringWithFormat :方法。

You can also use plain stringWithFormat: method.

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

这样你可以通过在字符串之间添加somethig来操作字符串,如:

This way you can manipulate string even more by putting somethig inbetween the strings like:

NSString *combined = [NSString stringWithFormat:@"%@/someMethod.php?%@", stringURL, stringSearch];

这篇关于如何在Objective-C中为iPhone应用程序组合两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆