LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data extraction from string

I'm trying to search a particular value in a string file. The string contains many parameters followed by their values and units. I want to identify and extract, as a number, the value of a particular parameter. The program will basically ask the user to type in (or select from a list of given) parameters in a dialogue box. Then it should display the value of the parameter.

 

The string I'm trying to work with, is of the form:-

 

SensorOneInMM,34585
BatteryVoltageInmV,19761
BattTemp1InC,20
CliffDistanceLeftInMM,60
CliffDistanceRightInMM,60
RightSensor,0
LeftSensor,0
CurrentInmAforMotor, 789
TestingCurrentInmA, 123
Temp1InC,28
Temp2InC,28
BaseCurrentInmA,1342
ChargeInmV,218
CurrentInmA,9999
NotConnected3,0

 

Now, for example the value I want to read is the one in Blue color. But the expression, "CurrentInmA" appears several times, in the string. How can I identify the value of the parameter in Blue color??

 

Thanks for helping out an amateur!!!

Cheers.

0 Kudos
Message 1 of 6
(3,052 Views)

Hi RAJ,

 

There are plenty of ways to do what you are after, here is just one:

 

Find string.png

 

Im sure there are better ways though,

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 2 of 6
(3,044 Views)

 

This will also do the job:

 

 

Extract.png

 

MC

Message 3 of 6
(3,031 Views)

Rajat

I think  you want to extract the value from specific string..

 

you can get number of post releted to your question...few are follow

Post 1

Post2

 

also see attached vi which specific to your problem..

0 Kudos
Message 4 of 6
(3,019 Views)

 

I like to use Match Regular Expression.

 

^ locks the match to the begining of a line.

(\d+) will return just the digits out the submatch. Expand the Match Regular Exptession down to add submatch output.

 

stripValue.png

Omar
Message 5 of 6
(2,971 Views)

Kudo to Omar for the use of submatch. An alternate to Omar regular expression can be \bCurrentInma,(\d+) where \b is a word boundary (match between a word character, letter-digit-underscore and a non-word character), in that case you don't have to set the multiline input to TRUE.

0 Kudos
Message 6 of 6
(2,949 Views)