update 1
Building on the previous update, I think I have a better insight into doing this, but I need the answer to this question. In the current for
loop there is a variable named tstring
. I need to do a something like the following, but it does not work. I get the error Collection expression type 'NSString *' may not respond to countByEnumeratingWithState:objects:count:'
How can I fix this for
clause?
for (NSUInteger i = 1; i < match.numberOfRanges; ++i)
{
NSRange matchedRange = [match rangeAtIndex: i];
NSString* tstring = [string substringWithRange: matchedRange];
for (char* suit in tstring){ // error here ********
NSLog(@"char: %@",suit);}
NSLog(@"range %lu string: %@", (unsigned long)i, tstring);
}
update 1
update 0
Here is another approach, that does not require a search, but I still don't have any idea how to accomplish this approach in the context of the for loop.
I need a dictionary like the following schematic representation which associates with each card (2 to Ace) an integer from 0 to 12. (I think I know how to create a dictionary in C; maybe not in objective-c.)
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬──┬──┬──┐
│0│1│2│3│4│5│6│7│8│9│10│11│12│
├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼──┼──┼──┤
│2│3│4│5│6│7│8│9│T│J│Q │K │A │
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴──┴──┴──┘
I need a struct with four nouns or arrays, I am not sure which, each of length 13 like this. This is similar to the original struct, but now the members are card suits, not players' positions.
struct board {
int num;
char spade[13]
char heart[13]
char diamond[13]
char club[13]
};
Assuming the following deal of Board number 1,
Q952.652.KJT4.95 T.KQT84.A865.J73 K8763.A7.Q.KQT84 AJ4.J93.9732.A62
I need the following process in the for loop of my code.
spade[10] = N
spade[7] = N
spade[3] = N
spade[0] = N
heart[4] = N
heart[3] = N
etc.
The question is, "How do you do that processing in a for loop?"
update 0
The following code is working for me but I need to alter it for the purpose described below. My console output (at least, the beginning) is provided below, also. From the output I need to retain results of range 1 and range 4 thru 19 in a special way.
The little table below contains range numbers in a 4 by 4 array with rows labeled Spades, Hearts, Diamonds, Clubs and columns labeled North, East, South, and West. When a Heart is selected, I need to search the contents of row H to determine whether that card is in N,E,S, or W and report the result. Notice that in the table the contents of each cell is a string containing either nothing (is empty) or a set of letters from '23456789TJQKA' and each row has all 13 letters somewhere in it. The numbers in the table just refer to the range number in the current output.
N E S W
S 4 8 12 16
H 5 9 13 17
D 6 10 14 18
C 7 11 15 19
I would like to learn how to store the results in anticipation of the search task. Can I create a C struct for which each member contains the integer board number (a number between 1 and 36) and the 4 strings? For example would the struct below work? And if it does, how does one search in such a struct in objective-c? I could also use some help populating the struct in my loop.
struct board {
int num;
char N[13]
char E[13]
char S[13]
char W[13]
};
Code excerpt follows.
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:toMatch options:NSRegularExpressionDotMatchesLineSeparators error:&error];
NSLog(@"pattern length: %lu", (unsigned long)[toMatch length]);
NSUInteger numberOfMatches = [regex numberOfMatchesInString:string options:0 range:NSMakeRange(0, [string length])];
NSLog(@"number of matches: %lu", (unsigned long)numberOfMatches);
for (NSTextCheckingResult* match in [regex matchesInString:string options:NSRegularExpressionDotMatchesLineSeparators range:NSMakeRange(0, [string length])])
{
NSLog(@"Number of ranges in match: %u", match.numberOfRanges);
for (NSUInteger i = 0; i < match.numberOfRanges; ++i)
{
NSRange matchedRange = [match rangeAtIndex: i];
NSString* tstring = [string substringWithRange: matchedRange];
NSLog(@"range %lu string: %@", (unsigned long)i, tstring);
}
}
Sample output follows.
2013-02-04 16:24:06.583 [71684:11303] string length: 22365
2013-02-04 16:24:06.591 [71684:11303] pattern length: 347
2013-02-04 16:24:06.602 [71684:11303] number of matches: 36
2013-02-04 16:24:06.613 [71684:11303] Number of ranges in match: 20
2013-02-04 16:24:06.613 [71684:11303] range 0 string:
[Board "1"]
[West ""]
[North ""]
[East ""]
[South ""]
[Dealer "N"]
[Vulnerable "None"]
[Deal "N:Q952.652.KJT4.95 T.KQT84.A865.J73 K8763.A7.Q.KQT84 AJ4.J93.9732.A62"]
2013-02-04 16:24:06.613 [71684:11303] range 1 string: 1
2013-02-04 16:24:06.613 [71684:11303] range 2 string: N
2013-02-04 16:24:06.614 [71684:11303] range 3 string: None
2013-02-04 16:24:06.614 [71684:11303] range 4 string: Q952
2013-02-04 16:24:06.614 [71684:11303] range 5 string: 652
2013-02-04 16:24:06.614 [71684:11303] range 6 string: KJT4
2013-02-04 16:24:06.614 [71684:11303] range 7 string: 95
2013-02-04 16:24:06.614 [71684:11303] range 8 string: T
2013-02-04 16:24:06.614 [71684:11303] range 9 string: KQT84
2013-02-04 16:24:06.614 [71684:11303] range 10 string: A865
2013-02-04 16:24:06.615 [71684:11303] range 11 string: J73
2013-02-04 16:24:06.615 [71684:11303] range 12 string: K8763
2013-02-04 16:24:06.615 [71684:11303] range 13 string: A7
2013-02-04 16:24:06.615 [71684:11303] range 14 string: Q
2013-02-04 16:24:06.615 [71684:11303] range 15 string: KQT84
2013-02-04 16:24:06.616 [71684:11303] range 16 string: AJ4
2013-02-04 16:24:06.616 [71684:11303] range 17 string: J93
2013-02-04 16:24:06.616 [71684:11303] range 18 string: 9732
2013-02-04 16:24:06.616 [71684:11303] range 19 string: A62