private void btnDamerauLevenshtein_Click(object sender, EventArgs e)
        {
            clearAll();
            if ((rtbData.Text == "") || (txtInput.Text == "") || (insertDistance.Text == ""))
            {
                this.errorProviderDL.SetError(btnDamerauLevenshtein, "Одно из полей пустое");
            }
            else
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                List <string> allCloseWords = new List <string>();
                string        checker       = txtInput.Text.ToString();
                string        editLines     = rtbData.Text.ToString();
                int           maxDist       = Convert.ToInt32(insertDistance.Text.ToString());
                string        checkFromRTF  = "";
                int           i             = 0;
                int           length        = editLines.Length;
                int           minDist       = Int32.MaxValue;
                string        closestWord   = "";
                while (i < length)
                {
                    checkFromRTF = "";
                    while ((i < length) && (!checkIfNeededChar(editLines[i])))
                    {
                        i++;
                    }
                    while ((i < length) && (checkIfNeededChar(editLines[i])))
                    {
                        checkFromRTF += editLines[i];
                        i++;
                    }


                    int checkDist  = Metricas.GetDamerauLevenshteinDistance(checker, checkFromRTF);
                    int checkDist1 = Metricas.GetDamerauLevenshteinDistance(checker, checkFromRTF.ToLower());
                    if (checkDist1 == minDist)
                    {
                        allCloseWords.Add(checkFromRTF);
                    }
                    else if (checkDist1 < minDist)
                    {
                        allCloseWords.Clear();
                        allCloseWords.Add(checkFromRTF);
                        minDist     = checkDist1;
                        closestWord = checkFromRTF;
                    }
                    if (checkDist <= maxDist)
                    {
                        int index;
                        if (checkDotOrComma(editLines[i - 1]))
                        {
                            index = i - checkFromRTF.Length - 1;
                        }
                        else
                        {
                            index = i - checkFromRTF.Length;
                        }
                        rtbData.Select(index, checkFromRTF.Length);
                        rtbData.SelectionColor = Color.Red;
                    }
                }
                if (closestWord == "")
                {
                    lblMaybeYouSearched.Text = "Возможно вы искали: нет подходящих результатов";
                }
                else
                {
                    lblMaybeYouSearched.Text = "Возможно вы искали: " + closestWord + "?";
                }

                stopWatch.Stop();
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                     ts.Hours, ts.Minutes, ts.Seconds,
                                                     ts.Milliseconds);
                txtElapsedTime.Text = elapsedTime;
                int cnt = 0;
                foreach (string str in allCloseWords)
                {
                    if (str == closestWord)
                    {
                        cnt++;
                    }
                }
                if (allCloseWords.Count == 0)
                {
                    txtPercent.Text = Convert.ToString(0);
                }
                else
                {
                    txtPercent.Text = Convert.ToString((Convert.ToDouble(cnt) / Convert.ToDouble(allCloseWords.Count)) * 100.0);
                }
            }
        }
        private void btnDice_Click(object sender, EventArgs e)
        {
            clearAll();

            if ((rtbData.Text == "") || (txtInput.Text == "") || (insertDistance.Text == ""))
            {
                this.errorProviderD.SetError(btnDice, "Одно из полей пустое");
            }
            else
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                List <string> allCloseWords = new List <string>();
                string        checker       = txtInput.Text.ToString();
                string        editLines     = rtbData.Text.ToString();
                string        insertedDist  = insertDistance.Text.ToString();
                double        minDist       = 0.0;
                int           k             = 0;
                string        leftNum       = "";
                double        left          = 0.0;
                if (insertedDist.IndexOf('.') != -1)
                {
                    while (insertedDist[k] != '.')
                    {
                        leftNum += insertedDist[k];
                        k++;
                    }
                    left = Convert.ToDouble(leftNum);
                    k++;
                }

                double u        = 1.0;
                string rightNum = "";
                while (k < insertedDist.Length)
                {
                    rightNum += insertedDist[k];
                    u        *= 10;
                    k++;
                }

                double right = Convert.ToDouble(rightNum);
                right   = right / u;
                minDist = left + right;
                string checkFromRTF = "";
                int    i            = 0;
                string closestWord  = "";
                double maxDist      = 0.0;
                int    length       = editLines.Length;
                while (i < length)
                {
                    checkFromRTF = "";
                    while ((i < length) && (!checkIfNeededChar(editLines[i])))
                    {
                        i++;
                    }
                    while ((i < length) && (checkIfNeededChar(editLines[i])))
                    {
                        checkFromRTF += editLines[i];
                        i++;
                    }
                    double checkDist  = Metricas.GetDiceMatch(checker, checkFromRTF);
                    double checkDist1 = Metricas.GetDiceMatch(checker, checkFromRTF.ToLower());
                    if (checkDist1 == maxDist)
                    {
                        allCloseWords.Add(checkFromRTF);
                    }
                    else if (checkDist1 > maxDist)
                    {
                        allCloseWords.Clear();
                        allCloseWords.Add(checkFromRTF);
                        maxDist     = checkDist1;
                        closestWord = checkFromRTF;
                    }

                    if (checkDist >= minDist)
                    {
                        int index;
                        if (checkDotOrComma(editLines[i - 1]))
                        {
                            index = i - checkFromRTF.Length - 1;
                        }
                        else
                        {
                            index = i - checkFromRTF.Length;
                        }
                        rtbData.Select(index, checkFromRTF.Length);
                        rtbData.SelectionColor = Color.Red;
                    }
                }
                if (closestWord == "")
                {
                    lblMaybeYouSearched.Text = "Возможно вы искали: нет подходящих результатов";
                }
                else
                {
                    lblMaybeYouSearched.Text = "Возможно вы искали: " + closestWord + "?";
                }
                lblMaybeYouSearched.Text = maxDist.ToString();
                stopWatch.Stop();
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                     ts.Hours, ts.Minutes, ts.Seconds,
                                                     ts.Milliseconds);
                txtElapsedTime.Text = elapsedTime;
                int cnt = 0;
                foreach (string str in allCloseWords)
                {
                    if (str == closestWord)
                    {
                        cnt++;
                    }
                }
                if (allCloseWords.Count == 0)
                {
                    txtPercent.Text = Convert.ToString(0);
                }
                else
                {
                    txtPercent.Text = Convert.ToString((Convert.ToDouble(cnt) / Convert.ToDouble(allCloseWords.Count)) * 100.0);
                }
            }
        }