gpt4 book ai didi

ios - 总是将除一个对象之外的两个对象添加到数组中(否则错误)

转载 作者:行者123 更新时间:2023-11-28 23:04:10 26 4
gpt4 key购买 nike

我把行间的代码擦掉了,因为没什么特别的,只是在数组中添加了一个联系人。我认为这与括号有关。所以希望有人有好眼力并能告诉我,为什么它总是添加两次联系人:)

if ([string rangeOfString:@"00"].location == NSNotFound) {


if(lastName && ([lastName length] > 0)) {


NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(1, [str length] - 1)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=%@", ccode, Nummer, firstName, lastName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
}
else {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(1, [str length] - 1)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=""", ccode, Nummer, firstName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

}

} else if(lastName && ([lastName length] > 0)) {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(0, [str length] - 0)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=%@", ccode, Nummer, firstName, lastName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

}
else {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(0, [str length] - 0)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=""", ccode, Nummer, firstName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

}

if ([string rangeOfString:@"+"].location == NSNotFound) {

if(lastName && ([lastName length] > 0)) {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(1, [str length] - 1)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=%@", ccode, Nummer, firstName, lastName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

}
else {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(1, [str length] - 1)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=""", ccode, Nummer, firstName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

}

} else if(lastName && ([lastName length] > 0)) {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(3, [str length] - 3)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=%@", ccode, Nummer, firstName, lastName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];


}
else {

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *ccode = [prefs stringForKey:@"cc"];
NSString *fileName = [prefs stringForKey:@"onumber"];

NSString *str = number;
NSString *newNumber = [str substringWithRange:NSMakeRange(3, [str length] - 3)];
NSString *Nummer = [newNumber stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strURL = [NSString stringWithFormat:@"http://myserver/phpFile.php?number=%@%@&name=%@&lastname=""", ccode, Nummer, firstName];
NSString *webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:webStringURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

}

最佳答案

if ([string rangeOfString:@"+"].location == NSNotFound) 条件应该以 else 开头。

应该如下所示:

else if ([string rangeOfString:@"+"].location == NSNotFound)

此外,在第二个 if 行之前(下面提到)

if ([string rangeOfString:@"+"].location == NSNotFound))

您应该为第一个 if 关闭“}”。

关于ios - 总是将除一个对象之外的两个对象添加到数组中(否则错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9555060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com