reading and parsing strings

4 thoughts on “reading and parsing strings

  1. Hi,


    I am getting from serial port 2 , GPS string
    continously.  I am willing to catch only the strings which starts
    ‘$TGPS,’ and finish ‘*’char by separator ‘,’, end put each field into


    I need example code 



    Haim Rodrik

    1. Python has a string split function which makes an easy job to split first by  NMEA terminator <CR><LF> then by , .

      1. Thank you for reply,


        Its my first script using Python in my life. I used Java G24 before and assembly. I dont have so much examples for split function


        I can use the string end charactrs   , the gps module that i am using its customized string. 



        1. Hello!
          I do this things as shown below:
          #Module: GE864-GPS, Internal using of GPS
          import GPS
          x = GPS.getActualPosition() 
          #Get GPS data from internal Python module
          GPS_list = x.split(‘,’)
          #Split GPS data into list (throw the separators: ‘,’ )
          #Now, for example, parse some NMEA elements into variables:
          GPS_Fix = str(GPS_list[5])                 #VALUES: 0(invalid),2(2D),3(3D)
          GPS_Time = GPS_list[0][0:6]            #FORMAT: hhmmss.sss
          GPS_Spkm = str(GPS_list[7])           #VALUES: from  x.x   to xxx.x 
          Good Luck to You!