LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing Measurements

When my cheap scope outputs measurements, it sends a numeric value, and optional metric prefix, and an optional unit string; with no spaces between them.

I've got code working that does the parsing, but it's kind of ugly.  Can anyone come up with something cleaner?

paul_a_cardinale_0-1780070659169.png

 

0 Kudos
Message 1 of 6
(147 Views)

I added a comment to the end of your previous post about SI units.

 

You can tweak it a bit, (remove the space between digits and magnitude) but it should be able to parse a wide range of values.

 

Solved: Re: Format to Without Space Between Number and Unit - Page 4 - NI Community

0 Kudos
Message 2 of 6
(29 Views)

I posted an example of parsing an SI formatted string in your previous post

 

Solved: Re: Format to Without Space Between Number and Unit - Page 4 - NI Community

 

0 Kudos
Message 3 of 6
(104 Views)

Shorter? Yes. Cleaner? Debatable 😉

 

PARSER.png

 

Spoiler
The regex is (?:: )([0-9.]+[YZEPTGMkhdcmunpfa]?)([^->]+)
0 Kudos
Message 4 of 6
(76 Views)

Second version if you don't care if the units are in SI base units or not:

 

PARSER2.png

 

(Might need some additional support if there are more spaces somewhere between the number and unit)

0 Kudos
Message 5 of 6
(68 Views)

I think you could use.. %f to grab the base 10 mantisa.  Then concat "1" and next char.  Then %u for the exponent.  A quick run through Multiply would work after that.  If next char isn't a valid metric Prefix %u =1 and %f*%u=%f and next char is part of the unit string.


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 6
(65 Views)