private int checkEntityWords(Entity entity)
{
Word.Range range = currentSelection.Range;
range.Start = range.End;
string result = "";
String[] words = entity.content.Split(' ');
string temp = "";
bool isCharBeforeLastSpace = false;
for (int i = 0; i < words.Length; i++)
{
string lastWord = "";
do
{
// Move the start range index by one letter (left)
// This is to check the word before the current cursor
range.MoveStart(Word.WdUnits.wdCharacter, -1);
temp = range.Text;
isCharBeforeLastSpace = (temp != null) && (!temp.Equals(" ") && (!temp.Equals("\r")));
if (isCharBeforeLastSpace)
lastWord = temp + lastWord;
// Move the end range index by one word (left)
range.MoveEnd(Word.WdUnits.wdCharacter, -1);
} while (isCharBeforeLastSpace);
if (i == 0)
{
result = lastWord + " " + result;
}
else if (lastWord != null)
{
for (int j = 0; j < words.Length - 1; j++)
{
if (words[j].Trim().ToLower().Equals(lastWord.ToLower().Trim()))
{
result = lastWord + " " + result;
break;
}
}
}
}
return result.Trim().Count();
}