I'm receiving my data in a string through a serial port communication. That part is working fine. The data is in the following format:
Distance run: 36in.
Direction in degrees: 275
Total of person founds:11
New Person found in:
Lat/Long: 18.38891, -66.12174
Date: 5/4/2013 Time: 19:13:35.0
Total of person founds:12
New Person found in:
Lat/Long: 18.38891, -66.12175
Date: 5/4/2013 Time: 19:13:37.0
Distance run: 15in.
Direction in degrees: 215
Total of person founds:13
New Person found in:
Lat/Long: 18.38891, -66.12174
Date: 5/4/2013 Time: 19:13:39.0
Distance run: 30in.
Direction in degrees: 180
But this can vary a little cause in between of each blog of persons founds (which includes it position in lat/long, date and time) there can be another distance run and direction in degrees.
I've tried Regex but not sure on how to use it well. I even have a regular expression that extract only the numbers.
var xnumbers = Regex.Split(strFileName, @"[^0-9\.\-]+").Where(c => c != "." && c.Trim() != "");
What I want is to extract the specific value of let say distance run: which the first value is 36in and store it and so on. Then get the value of the direction in degrees and store it in another variable and finally get the lat & long and store it in other variable. I need this values to create a List to later use that data and plot it. I already have the drawing part.
I tried this:
I know this patter takes only in consideration that distance is 2 numbers only but that value can be 1 or 3 numbers (example: Distance Run: 1in or Distance run: 219 in)
string pattern = @"^Distance Run:(?<distance>.{2}),Direction in degrees:,(?<degress>. {3}),Lat/Long:(\+|\-)(?<latlong>.{18})$";
string distance = string.Empty;
string degrees = string.Empty;
string latlong = string.Empty;
Regex regex = new Regex(pattern);
if (regex.IsMatch(strFileName)) // strFileName is the string with the data
{
Match match = regex.Match(strFileName);
foreach (Capture capture in match.Groups["distance"].Captures)
distance = capture.Value;
foreach (Capture capture in match.Groups["degree"].Captures)
degrees = capture.Value;
foreach (Capture capture in match.Groups["Lat/Long"].Captures)
latlong = capture.Value;
}
But is not working. I would thank for any help and advice. Thanks in advance.
Fermat's Last Theoremif you are interested.) I submitted a comment to try and steer you in a useful direction. Do with that what you will. There a plethora of open source parsing tools and tutorials on the web.