If statement problem

Hi all
I have a problem where I am waiting for a command from a PC serial port. Once the command comes in I run through some if statements

The structure of the commands is all basically the same eg "cu50". The problem I have is It sees it matches two things both cu5 and cu50.

Any ideas would be much appreciated

while (Serial.available()) {
    delay(1);  //delay to allow buffer to fill 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
         
    if(readString=="?VS"){
        Serial.println("Box C");        
      }
     if(readString=="*IDN?"){
        Serial.println("Box C Voltage hybrid burden box");        
      }
    if(readString=="?SN"){
        Serial.println("Box C IP003");        
      }
    
     if(readString=="cu2.5"){               
        bdn = readString.substring(2,7);
        Unity2_5();
        Serial.println(bdn); 
        }
      if(readString=="cu5"){               
        bdn = readString.substring(2,7);
        Unity2_5();
        Serial.println(bdn); 
        }
        if(readString=="cu7.5"){               
        bdn = readString.substring(2,7);
        Unity2_5();
        Serial.println(bdn); 
        }
      if(readString=="cu10"){               
        bdn = readString.substring(2,7);
        Unity2_5();
        Serial.println(bdn); 
        }
        if(readString=="cu50"){               
        bdn = readString.substring(2,7);
        Unity2_5();
        Serial.println(bdn); 
        }

    }
 }     
//bdn = "";  
readString="";
Serial.flush();

The problem is the command is coming in one character at a time and you run through those if statements after each character. You should receive the entire string before running the if statements.

Cheers FIXED, this is what happens when you cut and paste.

Cheers FIXED, this is what happens when you cut and paste.

Please, post your modified codes that you managed to work following the message of Post#1. We are interested, for the benefit of other Forum Members, to get familiar with your programming style of catching the string ?VS (for example) and then taking decision.

Thanks,

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. Just use cstrings - char arrays terminated with 0.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example.
...R