# LabVIEW

cancel
Showing results for
Did you mean:

## compare and extract number from string

Hi, all

If I want to compare a requirement number and extract a number form a continuous data, . for example,

the string like this ( ******** 123 ******
*********456 ******
*********789*******)

and I have requiremnts that I need to extract the number is nearest greater 450, so in the above example, I need to pick 456.

How can I result it?

thanks
Message 1 of 18
(2,237 Views)

## Re: compare and extract number from string

here is one way to do it.

Paul <--Always Learning!!!

sense and simplicity.
Browse my sample VIs?
Message 2 of 18
(2,220 Views)

## Re: compare and extract number from string

Thanks Pana

I nearly understand the method to solve the problem. But I am quite new in labview and I don't know some of the function you draw in jpg. Can you upload the Vi and have a look.

Thanks again.

Message 3 of 18
(2,210 Views)

## Re: compare and extract number from string

Just extract all numbers into an array, then find the element with the smallest absolute difference. See attached (LabVIEW 7.0).

EDIT: Sorry, If by "Nearest greater" you mean the next higher number, you can use something like in my example II. (Also LabVIEW 7.0).

If you don't recognize an node, just right-click on it and select help. 🙂

You still need to add proper execption handling, e.g.:

• What if no element is greater?
• What if there are multiple solutions?
• What if the string does not contain any numbers?

Message Edited by altenbach on 10-13-2005 09:05 AM

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 4 of 18
(2,203 Views)

## Re: compare and extract number from string

The above example II matched "Nearest greater OR equal". If you want the next higher element if an element is equal to the comparison number, you an make a small modification as shown.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 5 of 18
(2,182 Views)

## Re: compare and extract number from string

Thanks a lot and I can find the answer .

and I have another questions, still like this

I have a string for example( *****123**** (some number-such as 0.01%)****
*****456**** (some number-such as 0.02%)****
*****789**** (some number-such as 0.03%)****

I still need to extract 456, but i also need to extract the 0.02%, (the number follow the 456), I have a idea, but maybe too complicated.

I just though when i got the 456, and match it with the original string and then extract the following number. but i am not quite sure how to do it?

Message 6 of 18
(2,171 Views)

## Re: compare and extract number from string

Before people jump into solving this problem, do you have any other surprises hidden in this string that will need to be evaluated?  Is the number with the % ALWAYS there or sometimes?  These things definitely affect the approach to the problem!  Are there a fixed number of * between the two numbers?  Can you post an example of a complete dataset that would be in this string?

Message Edited by Pana-man on 10-13-2005 03:42 PM

Paul <--Always Learning!!!

sense and simplicity.
Browse my sample VIs?
Message 7 of 18
(2,165 Views)

## Re: compare and extract number from string

I agree with Paul,  we need more info on the string structure:
• Is each pair on a seperate line?

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 8 of 18
(2,154 Views)

## Re: compare and extract number from string

Thanks

Please see the attach JPG file. IF I want to extract the number in the first red square and pick the second red square number which includs the %.

how to do it?

thanks

Message 9 of 18
(2,142 Views)

## Re: compare and extract number from string

srt,

Looking at what you have posted it is still a little unclear as to what you actually need.

Are you extracting that number for any reason? (say nearest to a certain number?)

If you send in an actual text file with that dataset on I will try and create an example code for you to try out but I also need to know what number you need to extract and why.

Many Thanx