private String generateSubstring(String[] words, ArrayList wordIndexes)
{
wordIndexes.Sort();
object[] arrayWordIndexes = wordIndexes.ToArray();
// Special case
if (wordIndexes.Count == 1)
{
return words[0] + " ...";
}
String result = "";
try
{
for (int i = 0; i < arrayWordIndexes.Count(); i++)
{
int wordIndex = (int)arrayWordIndexes[i];
if (i == 0)
{
// first word
result += words[wordIndex];
}
else
{
result += " ";
int prevWordIndex = (int)arrayWordIndexes[i - 1];
if (wordIndex - prevWordIndex != 1)
{
result += "... " + words[wordIndex];
}
else
{
result += words[wordIndex];
}
}
}
}
catch (Exception e)
{
return "";
}
return result;
}