fork(3) download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4. using System.Globalization;
  5.  
  6. namespace SODemo
  7. {
  8. class MainClass
  9. {
  10. private static readonly CultureInfo CInfo = CultureInfo.CreateSpecificCulture("en-US");
  11.  
  12. public static void Main (string[] args)
  13. {
  14. string segment = "51.54398, -0.27585;51.55175, -0.29631;51.56233, -0.30369;51.57035, -0.30856;51.58157, -0.31672;51.59233, -0.3354";
  15.  
  16. var re = new Regex(@"\s*(?<lat>[-+]?[0-9.]+),\s*(?<lon>[-+]?[0-9.]+)\s*;", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
  17.  
  18. var locations = re.Matches(segment).Cast<Match>().Select(m => new
  19. {
  20. Lat = decimal.Parse(m.Groups["lat"].Value, CInfo),
  21. Long = decimal.Parse(m.Groups["lon"].Value, CInfo),
  22. });
  23.  
  24. foreach (var l in locations)
  25. Console.WriteLine(l);
  26. }
  27. }
  28. }
  29.  
Success #stdin #stdout 0.08s 37288KB
stdin
Standard input is empty
stdout
{ Lat = 51.54398, Long = -0.27585 }
{ Lat = 51.55175, Long = -0.29631 }
{ Lat = 51.56233, Long = -0.30369 }
{ Lat = 51.57035, Long = -0.30856 }
{ Lat = 51.58157, Long = -0.31672 }