02-08-2019 09:01 AM
OK gentleman, I need your eyes and brainpower to help me find a better solution to this if there is one.
I have a phrase that I am extracting from SAP (via a view that was created) that will have words and numbers within this field. I've found that the numbers are in a decimal format.
Example: I weigh 250.45 pounds.
From this, I need to extract 250.45. I've done it using RegEx and with the Match Regular Expression Function but I am wondering if there is a faster, more efficient way. No other numbers would be present other than what you see in the example.
Thoughts?
Solved! Go to Solution.
02-08-2019 09:11 AM
If the phrase is always the same, same number of characters, you can use the Fract/Exp String to Number VI and enter an offset.
02-08-2019 09:24 AM
There is an example in labview\examples\general\strings.llb (Extract Numbers VI) that will extract numbers from sentences. It uses Match Pattern. I think that will be your best bet.
02-08-2019 09:42 AM
That'll work. Appreciate the assistance.
02-08-2019 09:52 AM - edited 02-08-2019 09:55 AM
Oh neat, for me the example was found here in 2017.
<LV Install>\examples\Strings\Extract Numbers with Match Pattern.vi
Earlier I was using regular expression of "\d+(\.\d+)?" but Match Pattern likely is more efficient for simple things.
EDIT: Oh and don't forget this has regional issues. This regular expression and the NI example both use the decimal point as the separate for the fractional part of a number and other countries use the comma. Code can be written which can be configured to use the system separator. I usually use a known math equation like the square root of 2, and convert that to a string then see what separator character is there.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord