How to compare string coming from serial communication to predefined string

SoftwareSerial esp01(2,3);
String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("testing serial comm");
  esp01.begin(9600);
}

void loop() {
  
  String msg = "led 1 is on ";
  while(esp01.available()>0)
  {
  readString = esp01.readStringUntil('\n');
  if(readString==msg)
  {Serial.println("String : "+readString);
  }}
  
}

Have you verified that the software serial link works as expected?

yes everything is working fine except comparison of strings

You're not using strings, you're using Strings

will that work
can u give me the sketch

string is not any kewword i think

Neither is String.
What's your point?

What is connected to the other end of the software serial?

esp01 i am sending the code wait

#include "thingProperties.h"
int D0 = 0;
int D2 = 2;
void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  pinMode(D0,OUTPUT);
  pinMode(D2,OUTPUT);
  
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  
}

/*
  Since Led is READ_WRITE variable, onLedChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLedChange()  {
  if(led ==HIGH)
  {digitalWrite(D0,HIGH);
  String msg = "led 1 is on ";
  Serial.println(msg);
  }
  else
{digitalWrite(D0,LOW);
  String msg = "led 1 is off ";
  Serial.println(msg);

  
  // Add your code here to act upon Led change
}

/*
  Since Led2 is READ_WRITE variable, onLed2Change() is
  executed every time a new value is received from IoT Cloud.
*/
void onLed2Change()  {
  if(led2 ==1)
  {
  digitalWrite(2,HIGH);}
  else
{digitalWrite(2,LOW);}

  // Add your code here to act upon Led2 change
}

But, String is a data type. If int (a data type) is a keyword, then why is String not a keyword?

yes everything is working fine except comparison of strings

readString = esp01.readStringUntil('\n');

What do you see if you print readString in the monitor?

The list of C++ keywords is published.
Why not look it up?

If i print immediately after esp01.read, Serial monitor prints the string received from esp01 but when i compare that string with predefined msg string then nothing is printed.

It is not in the list.

So, String is not a keyword -- simple Y/N answer!!!

The first thing done in your compare is to see if the lengths are equal. I am guessing they are not. Print the sizeof() each string.

Good idea, i will try tomorrow and reply. Thanks

When you have the lengths also try printing out character by character to see if you can find a difference.

How to do that

Print the HEX of each character.

Better still, print the length of the String.
sizeof String will always be a constant, regardless of the length, typically six, for an AVR, IIRC.