如何在Objective-C中为iPhone应用程序组合两个字符串
发布时间:2020-12-16 03:17:14 所属栏目:百科 来源:网络整理
导读:如何将“stringURL”和“stringSearch”组合在一起? - (IBAction)search:(id)sender;{stringURL = @"http://www.websitehere.com/index.php?s=";stringSearch = search.text;/* Something such as: stringURL_ = stringURL + stringSearch */[web loadReque
如何将“stringURL”和“stringSearch”组合在一起?
- (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_]]]; } 解决方法
菲利普举了个很好的例子.
您也可以使用纯stringWithFormat:方法. NSString *combined = [NSString stringWithFormat:@"%@%@",stringURL,stringSearch]; 这样,您可以通过将字符串放在字符串之间来操纵字符串,如: NSString *combined = [NSString stringWithFormat:@"%@/someMethod.php?%@",stringSearch]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |