Compare and replace text in large volumes of data

0

I have a data dictionary with a few abbreviations and I need to go through a list containing dozens and even hundreds of paragraphs in order to compare words and replace words with those abbreviations.

What is the alternative (or best way) to compare Strings for large volumes of data without using Replace?

    
asked by anonymous 11.04.2017 / 16:37

1 answer

1

I've never done anything like this, but from what I understand of your doubt, it would start with a code like this:

class Program
    {
        static void Main(string[] args)
        {
            List<Dicionario> dicionario = new List<Dicionario>();
            //Carrega o dicionário

            string texto = @"texto gigante aqui
era uma vez, blabla bla";
            string novoTexto = "";
            string[] linhas = texto.Split('\r');

            for (int l = 0; l < linhas.Length;l++)
            {
                string[] palavras = linhas[l].Split(' ');
                for (int p = 0; p < palavras.Length; p++)
                {
                    Dicionario d = dicionario.Find(x => x.Palavra.ToUpper() == palavras[p].ToUpper());
                    if (d != null)
                        palavras[p] = d.Abreviacao;

                    novoTexto += palavras[p] + " ";
                }

                novoTexto += "\r";
            }

            //Seu novo texto
            Console.Write(novoTexto);

        }

        class Dicionario
        {
            public string Palavra { get; set; }
            public string Abreviacao { get; set; }
        }
    }

There you will go through performance tests to try to improve something and see if that's what you really need.

I hope to have helped

    
11.04.2017 / 23:50