Doubt with foreach C # [closed]

-2

Please. see the code at this link: link and tell me why the phrase does not come out with the jumbled lyrics; if possible, give me an idea of how to do the same thing with ores line

string frase,frase0;
    Console.WriteLine("Digite a frase: ");
    frase0 = Console.ReadLine();
    frase = frase0; 
    foreach(var a in frase0) {
            if(a == 'a'){
                frase.Replace(a, 'g');
            }else if(a == 'b'){
                frase.Replace(a, 'h');
            }else if(a == 'c'){
                frase.Replace(a, 'e');
            }else if(a == 'd'){
                frase.Replace(a, 'j');
            }else if(a == 'e'){
                frase.Replace(a, 'k');
            }else if(a == 'f'){
                frase.Replace(a, 'l');
            }else if(a == 'g'){
                frase.Replace(a, 'm');
            }else if(a == 'h'){
                frase.Replace(a, 'n');
            }else if(a == 'i'){
                frase.Replace(a, 'o');
            }else if(a == 'j'){
                frase.Replace(a, 'p');
            }else if(a == 'k'){
                frase.Replace(a, 'q');
            }else if(a == 'l'){
                frase.Replace(a, 'r');
            }else if(a == 'm'){
                frase.Replace(a, 's');
            }else if(a == 'n'){
                frase.Replace(a, 't');
            }else if(a == 'o'){
                frase.Replace(a, 'u');
            }else if(a == 'p'){
                frase.Replace(a, 'v');
            }else if(a == 'q'){
                frase.Replace(a, 'w');
            }else if(a == 'r'){
                frase.Replace(a, 'x');
            }else if(a == 's'){
                frase.Replace(a, 'y');
            }else if(a == 't'){
                frase.Replace(a, 'z');
            }else if(a == 'u'){
                frase.Replace(a, 'a');
            }else if(a == 'v'){
                frase.Replace(a, 'b');
            }else if(a == 'w'){
                frase.Replace(a, 'c');
            }else if(a == 'x'){
                frase.Replace(a, 'd');
            }else if(a == 'y'){
                frase.Replace(a, 'e');
            }else if(a == 'z'){
                frase.Replace(a, 'f');
            }
        }
        Console.WriteLine(frase);

// this is just the part that is not working

    
asked by anonymous 01.09.2018 / 15:47

1 answer

1

I think the code below solves your problem with fewer lines, as long as the association between the letters is always the one you indicated in your question:

string frase0 = string.Empty;
char[] frase = null;
string abc = "abcdefghijklmnopqrstuvwxyz";

Console.WriteLine("Digite a frase: ");

frase0 = Console.ReadLine();
frase = frase0.ToCharArray();

for (int i = 0; i < frase0.Length; i++)
{
    int index = abc.IndexOf(frase0[i]);
    char newChar = '
string frase0 = string.Empty;
char[] frase = null;
string abc = "abcdefghijklmnopqrstuvwxyz";

Console.WriteLine("Digite a frase: ");

frase0 = Console.ReadLine();
frase = frase0.ToCharArray();

for (int i = 0; i < frase0.Length; i++)
{
    int index = abc.IndexOf(frase0[i]);
    char newChar = '%pre%';

    if (frase0[i] == ' ')
        continue;

    if ((index + 6) >= abc.Length)
        newChar = abc[0 + (6 - (abc.Length - index))];
    else newChar = abc[index + 6];

    frase[i] = newChar;
}

Console.WriteLine(new string(frase));
'; if (frase0[i] == ' ') continue; if ((index + 6) >= abc.Length) newChar = abc[0 + (6 - (abc.Length - index))]; else newChar = abc[index + 6]; frase[i] = newChar; } Console.WriteLine(new string(frase));
    
01.09.2018 / 18:22