jason jason - 10 months ago 50
C# Question

Parse a string which is HTML input

Is there an elegant way to get lat and lon values from this string using C#? Thanks.
String is like this :

<input type="hidden" name="myinput" id="myinput" value='{"lat":11.111111,"lon":22.222222}'>

Answer Source

Per my comment, this is how I'd do it. I'm not claiming to be awesome at Regex by any means. There's probably a better way.

var r = new Regex(@"""lat"":(?<lat>\d+\.\d+),""lon"":(?<lon>\d+\.\d+)");
var m = r.Match(@"<input type=""hidden"" name=""myinput"" id=""myinput"" value='{""lat"":11.111111,""lon"":22.222222}'>");
if ( m.Success )