LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Grab a double from a string phrase

Solved!
Go to solution

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?

0 Kudos
Message 1 of 5
(2,283 Views)

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. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 5
(2,280 Views)
Solution
Accepted by topic author Eric1977

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. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 3 of 5
(2,268 Views)

That'll work. Appreciate the assistance.

0 Kudos
Message 4 of 5
(2,258 Views)

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.

0 Kudos
Message 5 of 5
(2,251 Views)