ACPAddIn.AutoCompleteForm.generateSubstring C# (CSharp) Method

generateSubstring() private method

private generateSubstring ( String words, ArrayList wordIndexes ) : String
words String
wordIndexes System.Collections.ArrayList
return String
        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;
        }