LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting data from a string

I currently am using the attached VI to select data from a string and turn it into a numeric. When my temperature is read from the TC200 (thor labs temperature controler) at values of above 100 degrees I can no longer obtain data values. Below are two sample snipits of the data in string format. Any help would be greatly appreciated. Thanks.

 

 

tact?

113.1 C

>

 

tact?

62.4 C

>

 

0 Kudos
Message 1 of 8
(3,956 Views)

What part of this string will always be there? Will it always be:

"tact?"<linefeed>[Temperature]" C"<linefeed>">"

 

Your VI doesn't seem to work on either of the strings you put there. Based on what you said, shouldn't it work on the 62 degree one?

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 8
(3,940 Views)

Here is one way. I am sure you could do it with one regular expression though. I would just need a little time to figure it out.

Tim
GHSP
0 Kudos
Message 3 of 8
(3,928 Views)

OK here is the single regular expression version very simple.

Tim
GHSP
0 Kudos
Message 4 of 8
(3,899 Views)

I was playing around with this and it was taking me forever to figure it out and I was getting really frustrated... Turns out I accidentally wired the wrong string in to the input, so it was trying to parse the wrong string. Argghh, such is life.

 

This should do it the easiest and match your expression exactly if you end up trying to pull from a larger string.

ScanFromStringTact.png

Edit: Just change the string surrounding the "%f" to match what will always be there. If you want to output the "C" as a string as well in case that changes to "F" every once in a while, replace it with "%s" in the format string. and add an output from the Scan From String VI

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 5 of 8
(3,896 Views)

This is what I like to use when reading back measurment for instruments. I call it Find First Delimited Fractional

It finds the first number anywhere in the string that is seperated from other text by either \s \t \r \n , or you can add your own delimiters like = or ;

 

Skipping over any text that is not a number.

 

5.34

-5.34

+5.35

5.35e-4

5

 

For something like

Channel4 = 5.35 it will skip over the 4 and only return 5.35

Channel 4 = 5.35 it will return the 4 and not the 5.35

Find First Delimited Fractional Number in String.png

 

 

Omar
Message 6 of 8
(3,821 Views)

@Omar_II wrote:

This is what I like to use when reading back measurment for instruments. I call it Find First Delimited Fractional

It finds the first number anywhere in the string that is seperated from other text by either \s \t \r \n , or you can add your own delimiters like = or ;

 

Skipping over any text that is not a number.

 

5.34

-5.34

+5.35

5.35e-4

5

 

For something like

Channel4 = 5.35 it will skip over the 4 and only return 5.35

Channel 4 = 5.35 it will return the 4 and not the 5.35

 

 


Couldn't you accomplish the same thing using the Spreadsheet String to Array with multiple delimiters? You would still need to go through the array to find the numbers, but you would elminate the shift registers and it would allow you to inline the subVI.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 8
(3,798 Views)

@James.M wrote:

Couldn't you accomplish the same thing using the Spreadsheet String to Array with multiple delimiters? You would still need to go through the array to find the numbers, but you would elminate the shift registers and it would allow you to inline the subVI.


I have about a half dozen variations of this including some that return ALL delimited numbers in an array. I should have posted a simpler one that uses a regex to find a valid number string that can be in-lined. I wanted to them to think more general about this without focusing on the "tact?" or what ever is there. I wanted to focus on the number that they wanted and not so much on the stuff they did not want.

 

Most of my use cases have a lot of verbose wordage in the reply intended for human readable. Some times full sentences and paragraphs.

I find the Spreadsheet String to Array returns too many zeros, requires looping to find the value. I then can't tell is a zero is a valid number or is from a word that I should skip over. Plus I can only use a single delimiter. I do use it but for only the simplest of tables.

 

I rarely use the "Scan From Sting" by itself to find a number in a string. I find it is not very forgiving or flexable. You have the get your format string just right or you get an ERROR. This is what I should have posted. It does not care what comes before or after the number. "tact?" or no "tact?"

Find First Floating Point.png

But if you have something like "Channel_2 = 113.1 C"

It will find the "2" in Channel_2 first..

Omar
Message 8 of 8
(3,687 Views)