So from the poker application I'm working on.. I made major headway today, but noticed a glitch in the tracking of money.
As of right now, I am breaking the text file down line by line, and then analyzing the prefix attached to it to determine where to send the next few lines too(without giving too much away, I most of the time can establish EXACTLY what would be before the name, and have the beginning search aspect of this covered). I then go on to break the line down into an array separated by spaces to fetch other info like numbers, or actions based on " objectAtIndex:x" type of situations... but onto the problem
In a nutshell, players are allowed to have names with spaces in them, and there is no set way in the text files generated from pokerstars to descern where EXACTLY they begin and or end.
.txt example being like this
These are 3 examples of this one person named "pebos train," but that is not to say that they are the only lines throwing loops at me. The name could have even more spaces, or it could be something that I would expect to come after it, for example he could have the name "pebos folds a lot" then the line would look like "pebos folds a lot: folds" and if i just searched for the first existance of "folds" then it would give me the incorrect name, then the rest of the data will be incorrect.
So i've set about attempting to write a method to fetch the name, without knowing EXACTLY what will be after the name. I can however come up with a list of characters, such as ":" or "(" that will come after a name in given scenarios, but I was hoping to come up with a way to do it all in one function.
So far I can't find a way to hammer down a perfect method for either A: getting the full range(again mainly the end point) of a given name of a player, or B: figure out where a name ends in general because of the naming conventions allowed by pokerstars.
Any brilliant ideas? Has anyone else done something like this?
The function i'm using right now looks something like this:
I've thought about accepting a string, instead of an array as an argument, and searching for specific strings that would be an expected ending, however.. I always stumble back to the point of the name could have the ending string I'm searching for in it. And for some reason, searching FROM the end of the string to the beginning just does not seem like a good idea, especially when I could be looking for multiple options.... I know there is a better way, I just cannot think of it
As of right now, I am breaking the text file down line by line, and then analyzing the prefix attached to it to determine where to send the next few lines too(without giving too much away, I most of the time can establish EXACTLY what would be before the name, and have the beginning search aspect of this covered). I then go on to break the line down into an array separated by spaces to fetch other info like numbers, or actions based on " objectAtIndex:x" type of situations... but onto the problem
In a nutshell, players are allowed to have names with spaces in them, and there is no set way in the text files generated from pokerstars to descern where EXACTLY they begin and or end.
.txt example being like this
Code:
Seat 2: pebos train ($6.59 in chips)
pebos train: folds //(however this could be checks, bets, raises, calls....)
Seat 2: pebos train folded before Flop
These are 3 examples of this one person named "pebos train," but that is not to say that they are the only lines throwing loops at me. The name could have even more spaces, or it could be something that I would expect to come after it, for example he could have the name "pebos folds a lot" then the line would look like "pebos folds a lot: folds" and if i just searched for the first existance of "folds" then it would give me the incorrect name, then the rest of the data will be incorrect.
So i've set about attempting to write a method to fetch the name, without knowing EXACTLY what will be after the name. I can however come up with a list of characters, such as ":" or "(" that will come after a name in given scenarios, but I was hoping to come up with a way to do it all in one function.
So far I can't find a way to hammer down a perfect method for either A: getting the full range(again mainly the end point) of a given name of a player, or B: figure out where a name ends in general because of the naming conventions allowed by pokerstars.
Any brilliant ideas? Has anyone else done something like this?
The function i'm using right now looks something like this:
Code:
+(NSString *) getNameFromString: (NSArray *) anArray from:(NSString *) preString to: (NSString *) postString {
int start, finish;
start = 0;
BOOL done;
// we figure out the start point for the name by finding the end point of the pre-string
if ( preString != nil ) {
done = NO;
while (!done) {
if ([[anArray objectAtIndex: start] hasPrefix: preString]) {
start++;
done = YES;
}
start++;
}
}
//now we figure the the end point when we hit the word that the name should end on
done = NO;
finish = start + 1;
while (!done) {
if ([[anArray objectAtIndex: finish] hasPrefix: postString]) {
finish++;
if (![[anArray objectAtIndex: finish] hasPrefix: postString]) {
done = YES;
}
}
finish++;
}
NSString *tmpString = @"";
int i;
for ( i = start; i < finish; i++) {
tmpString = [tmpString stringByAppendingString: [anArray objectAtIndex: i]];
if ( (i + 1) < finish)
tmpString = [tmpString stringByAppendingString: @" "]; // this throws a space in the name where needed
}
return tmpString;
}
I've thought about accepting a string, instead of an array as an argument, and searching for specific strings that would be an expected ending, however.. I always stumble back to the point of the name could have the ending string I'm searching for in it. And for some reason, searching FROM the end of the string to the beginning just does not seem like a good idea, especially when I could be looking for multiple options.... I know there is a better way, I just cannot think of it