I have the following string:
+53.581N -113.587W 4.0 Km W of Edmonton, AB
In C# is there anyway to break this string out into Long. Latt. and then city state and discare the middle part?
So basically I want 3 strings:
Long
Latt
Location.
Is this possible with multiple forms of this string? They are in the same formate but obviously the data would be different.
Thanks
Use a regular expression to accomplish this - something like:
string input = @"+53.581N -113.587W 4.0 Km W of Edmonton, AB";
Match match = Regex.Match(input, @"^(?<latitude>[+\-]\d+\.\d+[NS])\s+(?<longitude>[+\-]\d+\.\d+[EW])\s+\d+\.\d+\s+Km\s+[NSEW]\s+of\s+(?<city>.*?),\s*(?<state>.*)$");
if (match.Success) {
string lattitude = match.Groups["lattitude"].value;
string longitude = match.Groups["longitude"].value;
string city = match.Groups["city"].value;
string state = match.Groups["state"].Value;
}
Just like in all languages, it's possible with the power of the oh-so-awesome Regular Expressions.
If you are unfamiliar with Regular Expressions, I suggest you learn them. They're awesome. Seriously.
Here's a tutorial to get started with .NET regexps:
http://www.radsoftware.com.au/articles/regexlearnsyntax.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With