我试图将变量附加到字符串但它显示错误。我在这里遗漏了一些非常容易的东西,但我的思绪却被枪毙了。
NSString *eID = [entertainmentArticle objectForKey:@"eID"];
NSURL *urla = [NSURL URLWithString:@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=",eID];
答案 0 :(得分:3)
只能在它们之间加一个逗号来连接2个字符串变量。试试这个:
NSURL *urla = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=%@",eID]];
答案 1 :(得分:1)
如果你要做的就是追加,你有几个选择:
一个。使用NSString& stringWithFormat:
NSString *eID = [entertainmentArticle objectForKey:@"eID"];
NSString *urlString = [NSString stringWithFormat:@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=%@", eID];
NSURL *urla = [NSURL URLWithString:urlString];
B中。使用NSString& stringByAppendingString:
NSString *eID = [entertainmentArticle objectForKey:@"eID"];
NSString *baseUrl = @"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=";
NSString *urlString = [baseUrl stringByAppendingString:eID];
NSURL *urla = [NSURL URLWithString:urlString];
℃。使用NSMutableString& appendString:
NSString *eID = [entertainmentArticle objectForKey:@"eID"];
NSString *baseUrl = @"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=";
NSMutableString *urlString = [NSMutableString stringWithString:baseUrl];
[urlString appendString:eID];
NSURL *urla = [NSURL URLWithString:urlString];
答案 2 :(得分:1)
试试这样: -
NSString *eID = [entertainmentArticle objectForKey:@"eID"];
NSString *url=@"http://www.mydomain.com/iostest/appPHPs/schedule.php?eID=";
NSURL *urla = [NSURL URLWithString:[url stringByAppendingString:eID];