Question

GPS: 48.8896 N - 2.37586 W

GPS: 52.6399 N - -1.1267 W

I have those coordinates data after reading from the HTML File, and I want to have a regex that separate then combine them as a string with a semicolon in the middle like 48.8896;2.37586 or 52.6399;-1.1267 .

How could the pattern be in this case? Thank you

Was it helpful?

Solution

Within given examples:

string output = string.Join(";", Regex.Matches("GPS: 48.8896 N - 2.37586 W", @"-?\d+\.\d+")
                                      .OfType<Match>()
                                      .Select(m => m.Value));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top