haw can arduino read a string ?

hello
i can't understand how arduino read a string ? in this code i the led is always on !

int rLed = 12;

void setup() {  
   Serial.begin (9600);    
   pinMode(rLed, OUTPUT);   
   digitalWrite(rLed, LOW); 
   }

void loop() {
   while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    }
    if(inputString == "on"){
       digitalWrite(rLed, HIGH);       
   }
   if(inputString == "off"){
      digitalWrite(rLed, LOW);       
   }
}

See Serial input basics

Hint: have you considered subtracting anything from the string?

Where is inputString defined? And if it is defined as a String object, get rid of it and use a char array instead. It will save you a noticeable amount of memory.

input string is defined as a string

sawi:
input string is defined as a string

Since your shift key appears to be broken, how can we know what you are talking about? What happens when you receive "on"? What happens when the next letter arrives? What is in inputString then?

Very basic serial code to control the arduino LED.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if (readString == "on")     
    {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");
    }
    if (readString == "off")
    {
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");
    }
    readString="";
  } 
}

it works very well !
thank you