2

I've got a string like this:

<point srsName="EPSG:4326(WGS84)">
<coordinates>121.7725934555,25.1508396138</coordinates>

How can I only get the values from this string, e.g 121.7725934555,25.1508396138?

3
  • Looks like XML to me. Commented Apr 24, 2013 at 3:10
  • XmlDocument or XmlSerializer Commented Apr 24, 2013 at 3:11
  • 1
    @Fendy: XDocument would be easier, assuming this is XML. I don't see a closing </point> Commented Apr 24, 2013 at 3:13

1 Answer 1

3

If the string is short and you do not need to parse anything else from it, you can use regex:

<coordinates>([^,]+),([^<]+)</coordinates>

The two capturing groups would get 121.7725934555 and 25.1508396138.

var str = @"<point srsName=""EPSG:4326(WGS84)"">
<coordinates>121.7725934555,25.1508396138</coordinates>";
var m = Regex.Match(str, "<coordinates>([^,]+),([^<]+)</coordinates>");
Console.WriteLine("'{0}' '{1}'", m.Groups[1], m.Groups[2]);

Here is a demo on ideone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.