Simple String comparison not working

You should not use the "String" class on an AVR based MCU's like the UNO because it may cause unwanted behavior which can be hard to debug. If you really have to, you could use the trim() function to remove blank characters:

String result = packet;
result.trim(); //Remove blank characters
if (result == "whatever") {
  //Do something
}