LabVIEW

cancel
Showing results for 
Search instead 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
0 Kudos
Message 1 of 18
(3,686 Views)
here is one way to do it.

Paul
Message 2 of 18
(3,669 Views)

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.

 

 

0 Kudos
Message 3 of 18
(3,659 Views)
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

Download All
Message 4 of 18
(3,652 Views)
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.
Message 5 of 18
(3,631 Views)
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?
 
 
 
0 Kudos
Message 6 of 18
(3,620 Views)

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
Message 7 of 18
(3,614 Views)
I agree with Paul,  we need more info on the string structure:
  • Is each pair on a seperate line?
Message 8 of 18
(3,603 Views)

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

0 Kudos
Message 9 of 18
(3,591 Views)

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

AdamB

National Instruments UK

Applications Engineering Team Leader | National Instruments | UK & Ireland
0 Kudos
Message 10 of 18
(3,571 Views)