NMEA { @NonNull static String cleanNmea(@NonNull String nmea) { final int sentenceStart = nmea.indexOf('$'); if (sentenceStart > 0) { nmea = nmea.substring(sentenceStart); } return nmea.trim(); }    }
@Test public void cleanNmea() { assertEquals("$GPFOO,0,1,2,3*99", NMEA.cleanNmea("$GPFOO,0,1,2,3*99")); assertEquals("$GPFOO,0,1,2,3*99", NMEA.cleanNmea("$GPFOO,0,1,2,3*99\n")); assertEquals("$GPFOO,0,1,2,3*99", NMEA.cleanNmea("$GPFOO,0,1,2,3*99\0")); assertEquals("$GPFOO,0,1,2,3*99", NMEA.cleanNmea("$GPFOO,0,1,2,3*99 ")); assertEquals("$GPFOO,0,1,2,3*99", NMEA.cleanNmea(" $GPFOO,0,1,2,3*99 ")); assertEquals("$GPFOO,0,1,2,3*99", NMEA.cleanNmea("\0$GPFOO,0,1,2,3*99 ")); }