简体   繁体   English

如何编写IF ELSE来检查数组的字符串内容?

[英]How do I write an IF ELSE to check string contents of an array?

I'm trying to write an IF ELSE statement to enable shipping, If user doesn't add an address the array contents remain as "-" & "-" for the two items in the array. 我正在尝试编写IF ELSE语句来启用传送,如果用户未添加地址,则数组内容对于数组中的两个项目仍为“-”和“-”。 I want to check to see if those are in the array, if they are then I want to enableshipping. 我想检查一下它们是否在数组中,如果它们在那儿,那么我想启用运输。

Here is the code for getting the array: 这是获取数组的代码:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullFileName = [NSString stringWithFormat:@"%@/arraySaveFile", documentsDirectory];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:fullFileName];

How do I write this first line to look for the "-" & "-"? 如何编写第一行以查找“-”和“-”?

if ([fullFileName isEqualToString:@"-","-"]) 
{
[nnNEP EnableShipping];
}
else {
    [nnNEP DisableShipping];
}

Thanks, 谢谢,

michael 迈克尔

I think you want to check the contents of the first two items of the array and not fullFileName. 我认为您想检查数组的前两项而不是fullFileName的内容。

For example: 例如:

if ([[array objectAtIndex:0] isEqualToString:@"-"] 
      && [[array objectAtIndex:1] isEqualToString:@"-"])
{
    [nnNEP EnableShipping];
}
else
{
    [nnNEP DisableShipping];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM