Click here to Skip to main content
16,010,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone .. I have a machine that sends data through serial port in this format.
_____________________
HSU-avg = 00 (HSU)
K-avg = 0.01
9 1930 2.8 0.01
8 1940 2.8 0.01
7 2190 2.8 0.01
6 1810 2.8 0.01
5 1970 18.8 0.02
4 2190 2.8 0.01
3 2150 2.8 0.01
2 2070 13.1 0.01
1 2150 25.7 0.02
------- ---- ----
MAX.RPM SEC. K.
OIL.TEMP = 0088
-----------------------
AVG :1040 2065
-------- -------
6 0830 2080
5 0660 1890
4 1340 1960
3 1330 2320
2 0690 2170
1 0840 2190
-------- -------
IDLE.RPM MAX.RPM
-----------------------

I currently use this
C#
Regex.Split(machinedata, @"[^0-9\.]+").Where(c => c != "." && c.Trim() != "");"
to extract the numbers into an array and then calculate them. Is there any other better way .. ??

My problem is not with the regex(regex works fine) . I am a beginner, So I would like to know the best practices like how you pro's deal with this sort of thing ..??
Posted
Updated 10-Jan-16 20:08pm
v7
Comments
Sergey Alexandrovich Kryukov 11-Jan-16 10:51am    
If not Regex, what's the problem?
—SA

This may help you to check that your RegEx do what you expect.
perlre - perldoc.perl.org[^]
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
Comments
Patrice T 11-Jan-16 2:17am    
You can always parse by yourself, but it get messy quickly.
Regex is the best deal, both easy and powerful.
Please refer link below it might be give answer of your question.
http://www.codeproject.com/Articles/9099/The-Minute-Regex-Tutorial
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900