如何在Objective-C中为iPhone应用程序组合两个字符串

前端之家收集整理的这篇文章主要介绍了如何在Objective-C中为iPhone应用程序组合两个字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将“stringURL”和“stringSearch”组合在一起?
  1. - (IBAction)search:(id)sender;{
  2. stringURL = @"http://www.websitehere.com/index.PHP?s=";
  3. stringSearch = search.text;
  4. /* Something such as:
  5. stringURL_ = stringURL + stringSearch */
  6. [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:stringURL_]]];
  7. }

解决方法

菲利普举了个很好的例子.

您也可以使用纯stringWithFormat:方法.

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

这样,您可以通过将字符串放在字符串之间来操纵字符串,如:

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

猜你在找的C&C++相关文章