Showing results for 
Search instead for 
Did you mean: 

Grab a double from a string phrase

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.



0 Kudos
Message 1 of 5

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. 

LabVIEW 2017
LabVIEW Programming
0 Kudos
Message 2 of 5
Accepted by topic author Eric1977
02-08-2019 07:42 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. 

LabVIEW 2017
LabVIEW Programming
Message 3 of 5

That'll work. Appreciate the assistance.

0 Kudos
Message 4 of 5

Oh neat, for me the example was found here in 2017.


<LV Install>\examples\Strings\Extract Numbers with Match


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 - Hooovahh - LabVIEW Overlord
Interesting in learning all you can about automotive CAN bus communication? Checkout my 12 part CAN Blog series.

0 Kudos
Message 5 of 5