If you use "while (Serial.available())" you will need to account for the times the serial input buffer has not been filled with a character (the arduino loops and checks the buffer much faster than the usual serial serial input can put something in the buffer. A slight delay can be one solution (a 1 ms delay may be all that is needed). There are also other various approaches to capturing strings.
// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial test 0021"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(10);
if (Serial.available() >0) {
char c = Serial.read();
readString += c;}
}
if (readString.length() >0) {
Serial.println(readString);
readString="";
}
}