I have a myString that i break into an array of words.
My goal is to determinate if the content of the myString mets the conditions:
- if myString contains all of "0", it prints out "Failed!"
- if myString contains all of "1", it prints out "Passed!"
- if myString contains a mixture of "1" and "0", it prints out "Partially Passed!"
Here is the code i try but it does not work in the while loop
Can you please help me, thanks!
My goal is to determinate if the content of the myString mets the conditions:
- if myString contains all of "0", it prints out "Failed!"
- if myString contains all of "1", it prints out "Passed!"
- if myString contains a mixture of "1" and "0", it prints out "Partially Passed!"
Here is the code i try but it does not work in the while loop
Can you please help me, thanks!
PHP:
NSString *myString = @"1 1 1 2 0 1 2 0 1 0";
//break NSString *myString into an NSArray containing
//the individual words separated by whitespace, newlines, and punctuation
NSMutableCharacterSet *separators = [NSMutableCharacterSet punctuationCharacterSet];
[separators formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSArray *words = [myString componentsSeparatedByCharactersInSet:separators];
NSEnumerator *enumerator;
enumerator = [words objectEnumerator];
NSString *stringContents;
NSString *result;
//cycles through array
//It does not work up to here:
while (stringContents = [enumerator nextObject]) {
if ([stringContents isEqualToString:@"0"]) {
result=@"Failed!";
}
if ([stringContents isEqualToString:@"1"]) {
result=@"Passed!";
}
if ([stringContents isEqualToString:@"0"] && [stringContents isEqualToString:@"1"]) {
result=@"Partially Passed!";
}
}
//print out result either failed, passed or partially passed.
//but it does not work with the output outside the loop.
NSLog(@"%@", result);