CeciliA CeciliA - 2 months ago 6
Java Question

How can i get the last lines of string in JAVA

$GPGGA,013810.000,1437.9098,N,12100.2297,E,1,10,1.0,26.4,M,39.1,M,,0000*69
$GPRMC,013810.000,A,1437.9098,N,12100.2297,E,0.00,122.34,200916,,,A*6A
$GPGGA,013811.000,1437.9098,N,12100.2297,E,1,10,1.0,26.4,M,39.1,M,,0000*69
$GPRMC,013811.000,A,1437.9098,N,12100.2297,E,0.00,122.34,200916,,,A*6A
$GPGGA,013812.000,1437.9098,N,12100.2297,E,1,10,1.0,26.4,M,39.1,M,,0000*69
$GPRMC,013812.000,A,1437.9098,N,12100.2297,E,0.00,122.34,200916,,,A*6A


Every Second I'm concatenating String of NMEA to a String Variable. All I want is to get the last $GPGGA and GPRMC because i need it for time and date. Is there a way to do that? Thanks in advance guys.

PEF PEF
Answer

If you have the following:

String a = "$GPGGA,013812.000,1437.9098,N,12100.2297,E,1,10,1.0,26.4,M,39.1,M,,0000*69";
String b = "$GPRMC,013812.000,A,1437.9098,N,12100.2297,E,0.00,122.34,200916,,,A*6A";

Then split each at the "," symbol:

String[] aAry = a.split(",");
String[] bAry = b.split(",");

I think the second element of each array (index 1) contains the time so it can be accessed as aAry[1] which contains the string 013812.000 (as does bAry[1]). I'm not sure where the date is stored in these strings.

Comments