serially read string comparison with another string value

hi friends,
I am not getting any serial output even while "first" or "second" is serially read.
please point out my error.

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0)
  {
    String a = Serial.readString();
    if (a == "first")
      Serial.println("first selected");
    if (a == "second")
      Serial.println("second selected");
  }
}

In the serial monitor window set line endings to None and try it. The problem is that the serial monitor is sending extra characters like a carriage return and/or line feed.

"first\r\n" or "first\n" does not equal "first".

line ending.jpg

I am not getting any serial output even while "first" or "second" is serially read.
please point out my error.

Make sure that the serial monitor is set up for "No line ending". It is set in a pull down menu next to the baud rate selection box.

Rather than use Strings, and the Serial.readString() method, you should look at Robin2's tutorial on serial input for better methods.

https://forum.arduino.cc/index.php?topic=396450.0

Thank you