cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Grab a double from a string phrase

Solved!
Go to solution
Highlighted

Grab a double from a string phrase

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
(106 Views)

Re: Grab a double from a string phrase

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

Re: Grab a double from a string phrase

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
LabVIEW 2017
LabVIEW Programming
Message 3 of 5
(91 Views)

Re: Grab a double from a string phrase

That'll work. Appreciate the assistance.

0 Kudos
Message 4 of 5
(81 Views)

Re: Grab a double from a string phrase

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 - 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
(74 Views)