Poker Prof
Poker Prof

Reputation: 169

Labview: Extract Digit Values from This String

This should be quite simple for the experts.

How do I extract the value 2.11 from this string !IR1= -2.11:24
OR extracting 3.27 from this strong !IR1= 3.27:88

Thank you!

Regards, Prof

Upvotes: 0

Views: 5867

Answers (2)

edupo
edupo

Reputation: 99

When scanning a Real number I always recommend to explicitly specify the decimal separator character in the format string.

Using the vi Programming/String/Scan From String you should use a format string like %.;!IR1= %f.

String %.; at the beginning of the format string tells LabVIEW that your decimal separator is a dot (.), independently from Format settings of your OS or in LabVIEW.

Not specifying this decimal separator is a common mistake that could lead to unexpected results if you plan to use your code in several computers.

Upvotes: 3

nekomatic
nekomatic

Reputation: 6284

VI snippet showing scan from string

This shows how to use Scan From String to get at the value you want. Note that there's a space between the open square bracket and the hyphen. This matches any number of spaces and/or hyphens between the text !IR1= and the numeric value.

This image is a VI snippet so you should be able to drag it right on to your LabVIEW diagram and use the code.

If you right-click on Scan From String and choose 'Edit Scan String' you get this dialogue:

screenshot of Edit Scan String window

which helps you to assemble the scan string you want. Note that it puts spaces in between each of the scan items by default, which you may not want. To get more help on constructing scan strings, see the LabVIEW help for Scan From String.

Upvotes: 3

Related Questions