Compare and replace text in large volumes of data

Asked

Viewed 128 times

0

I have a data dictionary with some 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 Large Data Strings Without Using Replace ?

  • It’s C# or VB.NET?

  • It is csharp, to define whether it will be web.api or Ws or wcf

  • Hello Adriano. This dictionary has how many abbreviations, approximately?

  • So far 300 abbreviations

  • some progress ?

  • Hello @Rovann Linhalis, I had to be directed to another activity and as soon as I can I will implement this suggestion and do some performance tests, as soon as I resume I give a feedback.

Show 1 more comment

1 answer

1


I’ve never done anything like this, but from what I understand of your doubt, I’d 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; }
        }
    }

then I would do performance tests to try to improve something and see if this is really what you need.

hope I’ve helped

  • I will implement and make some tests and I will give a return, shelter

Browser other questions tagged

You are not signed in. Login or sign up in order to post.