Closed Prajwal-Koirala closed 11 months ago
package main import ( "fmt" "strconv" "strings" ) func main() { str := "[iso: 110] [shutter: 1/1250.0] [fnum: 2.8] [ev: 0] [ct: 5480] [color_md : default] [focal_len: 24.00] [latitude: 40.73069] [longitude: -73.84002] [rel_alt: 72.400 abs_alt: 79.206] </font>" latIndex := strings.Index(str, "latitude:") // find the index of "latitude:" in the string if latIndex == -1 { fmt.Println("No latitude found in the string") return } latIndex += len("latitude:") // adjust the index to the end of "latitude:" lonIndex := strings.Index(str, "longitude:") // find the index of "longitude:" in the string if lonIndex == -1 { fmt.Println("No longitude found in the string") return } latStr := strings.TrimSpace(str[latIndex:lonIndex]) // extract the latitude string if idx := strings.IndexByte(latStr, ']'); idx != -1 { latStr = latStr[:idx] } lonStr := strings.TrimSpace(str[lonIndex+len("longitude:"):]) // extract the longitude string if idx := strings.IndexByte(lonStr, ']'); idx != -1 { lonStr = lonStr[:idx] } lat, err := strconv.ParseFloat(latStr, 64) if err != nil { fmt.Println("Error parsing latitude:", err) return } lon, err := strconv.ParseFloat(lonStr, 64) if err != nil { fmt.Println("Error parsing longitude:", err) return } fmt.Printf("Latitude: %f, Longitude: %f\n", lat, lon) }