LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to search for a number located anywhere in string

Solved!
Go to solution

I am trying to search a string for a number (integer or float) without knowing its index in the string and to extract it - whether in numeric or string format.  e.g. "the number 52.63 appears in this string"; I want to extract/identify "52.63"

 

The functions I come across seem to expect the index to be known or the number to be at index 0.  How can I achieve this?

 

Best regards.

 

Kenoss

0 Kudos
Message 1 of 11
(7,448 Views)

Use the Search/Split Screen primitive. I'm sure there are plenty of examples in the Find and Example screen.

PaulG.

LabVIEW versions 5.0 - 2023

“All programmers are optimists”
― Frederick P. Brooks Jr.
0 Kudos
Message 2 of 11
(7,442 Views)
Are there other numbers expected in the string? If not you can parse the string based on using the space between words as a delimiter, checking each "word" to see if it is a number.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 3 of 11
(7,431 Views)

LabVIEW does not seem to have a function to pull any number from a string. We have an example of a way this can be done LV 8.6.1

 

Hope this helps

 

0 Kudos
Message 4 of 11
(7,426 Views)

I forgot the warning for my the previous example. If the string contains multiple numbers in various locations in the string, all numbers will get concatenated into one output number.

 

IE: a string like- "Yes 12 months and 5 days is acceptable"- would have an output of 125

0 Kudos
Message 5 of 11
(7,418 Views)

Thanks all for your variety of ideas which are very helpful!!  I found using "[-]?[.]?[0-9]+[.]?[0-9]*" in regular expression input of Match Pattern function does the trick.  Am investigating the individual meanings of this regular expression.

 

Many thanks.

0 Kudos
Message 6 of 11
(7,415 Views)

kenoss wrote:

Thanks all for your variety of ideas which are very helpful!!  I found using "[-]?[.]?[0-9]+[.]?[0-9]*" in regular expression input of Match Pattern function does the trick.  Am investigating the individual meanings of this regular expression.

 

Many thanks.


I was about to explain, but I figured it would be quicker to just post the 'LabVIEW Help' details.

 

help.jpg

 

Help 2.jpg

Cory K
0 Kudos
Message 7 of 11
(7,369 Views)

If you are about to dive into the 'wonderfull world of Regular Expression' don't miss this (regular-expressions.info) site.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 8 of 11
(7,366 Views)

Check out [LabVIEW]\examples\general\strings.llb\Extract Numbers.vi.  Seems to work well on the example string you give in your initial post.  Is this what you were looking for?

0 Kudos
Message 9 of 11
(7,359 Views)
Thats where I got the idea Darren, there are alot of interesting add-ons out there!...
0 Kudos
Message 10 of 11
(7,337 Views)