String to Float, but for Dummies

Problem statement: I'm returning a string from a camera, I'm parsing the string into a dataset, and I'm left with 4 strings.

//Pre parsed:
UC TEUUU S1.000 I51.5

//Post Parse
UC
TEUUU
S1.000
I51.5

Then I want to use that 4th value for some events so I want to convert it to a float and ditch the I.

This thread from 2012 is very helpful as it's same question.

But I don't have it going to a database outside of a Data List Tag that I've derived doing this:
split({source}," ")

Then a reference tag that I built doing this:
[.]Data List[3,0]

So I've isolated that value, and I want to make a tag that has the float result so I can alarm or do other process control things with it.

I understand the script from the 2012 thread, but am wondering do I perform that on the cell and then write that to a new (3rd?) tag? I think this is clunky because of my lack of knowledge and a smart kid would do it differently.

Using a substring() expression can help:
toFloat(substring({[.]Data List}[3,0],1))

FWIW, using a UDT would be useful if you have more than one camera. Point the raw value at the camera input
udt_Camera.json (1.1 KB)

6 Likes

Yeah solved.Thank you.
I agree on UDT, I have to stick build a working single tag first before I can optimize but that's just my inability to jump twice at once.

I didn't know I could directly convert from a list like that, this is really slick and I appreciate this. It opens up other options unrelated to this specific question as well.

Datasets, list-like sequences, and associative key/value pairs (aka maps, dictionaries) can all be extracted with 'subscript' syntax:

1 Like