<SOLVED> Problem with serial and string functions

I'm trying to do a letter replacement process to codify text, so I'm testing with the serial, but it doesn't show on the Serial monitor, so I don't know if the problem is the Serial bit, or the process bit that's badly programmed, can someone please help? I've beeen strugling for the past two hours and I already don't know what to do :frowning: . Here's the code:

edit: sorry, there was an extra line that had nothing to do with the code, now it's the code that is giving me problems.

String raw = "";
String codif = "";

void setup() {

  Serial.begin(9600);

}

void loop() {

  raw = Serial.readString();
  Serial.println(raw);
  substi();
  Serial.println(codif);
  delay(5000);

}

void substi(){

  int i;
  while(raw.length() >= codif.length()){
    if( raw.charAt(i) ==  'a'){
      codif = codif + 'c';
    }
      
    if( raw.charAt(i) ==  'b'){
      codif = codif +  'd';
    }
      
    if( raw.charAt(i) ==  'c'){
      codif = codif +  'e';
    }
      
    if( raw.charAt(i) ==  'd'){
      codif = codif +  'f';
    }
      
    if( raw.charAt(i) ==  'e'){
      codif = codif +  'g';
    }
      
    if( raw.charAt(i) ==  'f'){
      codif = codif +  'h';
    }
      
    if( raw.charAt(i) ==  'g'){
      codif = codif +  'i';
    }
      
    if( raw.charAt(i) ==  'h'){
      codif = codif +  'j';
    }
      
    if( raw.charAt(i) ==  'i'){
      codif = codif +  'k';
    }
      
    if( raw.charAt(i) ==  'j'){
      codif = codif +  'l';
    }
      
    if( raw.charAt(i) ==  'k'){
      codif = codif +  'm';
    }
      
    if( raw.charAt(i) ==  'l'){
      codif = codif +  'n';
    }
      
    if( raw.charAt(i) ==  'm'){
      codif = codif +  'o';
    }
      
    if( raw.charAt(i) ==  'n'){
      codif = codif +  'p';
    }
      
    if( raw.charAt(i) ==  'o'){
      codif = codif +  'q';
    }
      
    if( raw.charAt(i) ==  'p'){
      codif = codif +  'r';
    }
      
    if( raw.charAt(i) ==  'q'){
      codif = codif +  's';
    }
      
    if( raw.charAt(i) ==  'r'){
      codif = codif +  't';
    }
      
    if( raw.charAt(i) ==  's'){
      codif = codif +  'u';
    }
      
    if( raw.charAt(i) ==  't'){
      codif = codif +  'v';
    }
      
    if( raw.charAt(i) ==  'u'){
      codif = codif +  'w';
    }
      
    if( raw.charAt(i) ==  'v'){
      codif = codif +  'x';
    }
      
    if( raw.charAt(i) ==  'w'){
      codif = codif +  'y';
    }
      
    if( raw.charAt(i) ==  'x'){
      codif = codif +  'z';
    }
      
    if( raw.charAt(i) ==  'y'){
      codif = codif +  'a';
    }
      
    if( raw.charAt(i) ==  'z'){
      codif = codif +  'b';
    }
      
    if( raw.charAt(i) == " "){
      codif = codif +  " ";
    }

    i++;

  }

}

Do you have a version of your code with meaningful comments?

Your code does not compile.

Have you posted the correct (very inefficient) version ?

There are much easier ways to shift the alphabet two letters, if that is what you are doing (I haven't checked every if statement to verify). Even if the letter replacement isn't a linear function, would be easier to use the original character as an index into a lookup table, than to test for each individual character.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

Robin2:
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

Thanks for the advice, I was able to resolve it thanks to you.