Script in c# that reads characters and Replace characters

Asked

Viewed 57 times

-1

A Program in c# that reads a string string, and prints it on the console in such a way that the vowels are replaced,.

  • Come on, it’s not worth the hyena ... You need to make a face ... and bring us doubts

  • I don’t really know how to proceed with community rules, but I do know that I really need help... @Virgilionovic

1 answer

0


I didn’t quite understand what you wanted, but it would be something like this ?

string line = "testandoyyiiaaaccccbbb";

    //Busca o caractere que mais se repete.
    var maxRepeat = line.ToArray()
                  .GroupBy(x => x.ToString())
                  .ToDictionary(x => x.Key,
                                x => x.Count(), 
                                StringComparer.OrdinalIgnoreCase)
                  .OrderByDescending(x => x.Value)
                  .First();

    //Troca todas as vogais pelo caractere que mais se repete.
    var result = line.Replace("a", maxRepeat.Key)
                      .Replace("e", maxRepeat.Key)
                      .Replace("i", maxRepeat.Key)
                      .Replace("o", maxRepeat.Key)
                      .Replace("u", maxRepeat.Key);

    Console.WriteLine($"Caractere que mais se repete: {maxRepeat.Key}");
    Console.WriteLine(result);
    Console.ReadLine();
  • 2

    When you don’t understand, you don’t answer. The question is just a statement and Rena has no way to be answered properly. I’m pretty sure that code is not what the person actually wanted, because it can do something much better, and that’s why we didn’t answer that. It may be an answer, but it’s not a good one, it teaches people something bad.

Browser other questions tagged

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