I’m trying a simple comparison here, assignment doesn’t work as i would like… here is the code,
int returnDateIndex(Paragraph para)
{
long firstIndex = 0;
for (int i = 0; i < para.Words.Count; i++)
{
if (para.Words[i].Text == "Second")
{
if (para.Words[i - 1].Text == "First")
{
firstIndex = para.Words[i].FirstSymbolPosition;
}
}
}
return (int)firstIndex;
}
I ran my debugger (In VS) and when that assignment is called, the int on the right was equal to 50, but the int on the left stayed equal to 0. No idea what I’m missing.
This application is using the Abbyy FineReader 9.0 SDK and the documentation for FirstSymbolPosition says it returns a read-only Long
EDIT: the code has been stripped of all features to make it easier for viewers to see where the problem is. I would appreciate answers for the original questions and anything else with the code that is bugging you as a comment please.
One obvious error is that you’re expecting to return the first case where your conditions match (hence the firstIndex variable name), but you’re really returning the last point where they match. This is also bad because it means you keep looking after finding your match. Another is that if the very first word in a sentence is “Second”, you’ll try to reference a negative index, which is very bad. Try this instead:
This code fixes both errors, and also completely side-steps your assignment problem.