Expression: get 3rd to last element of split(..) result

In an alarm Display Path binding, I want to use the folder name 2 parents below where the alarm resides, but am struggling to find information about how to do this. I can’t see a way to get the number of rows in a dataset using the expression language.

e.g. alarm tag path:
Winery/Receivals/Crushers/DC2001/Flush Valve/Alarms/Failed to Open

I’d like the display path to be:
‘Crusher 1 Flush Valve Failed to Open’
which means pulling out ‘Flush Valve’ from the tag path. I would like the expression to be as re-usable as possible so that I can use it in any location, and fix itself if ever the parent device folder (e.g. DC2001) is moved.

So far I have:
split({itemPath}, ‘/’)[row,0]
where ‘row’ needs to be replaced with psuedo-code (count-3) (’-3’ as index starts at 0)


I don’t have designer open right now but could you use concat?

concat(split({itemPath},’/’)[2,0],’ ‘,split({itemPath},’/’)[3,0], ’ ‘,split({itemPath},’/’)[6,0])

The expression function len() (somewhat confusingly, placed in the ‘Strings’ section) works directly on datasets - so you can work backwards from the number of rows that way.

How about:

str = 'Winery/Receivals/Crushers/DC2001/Flush Valve/Alarms/Failed to Open'
print str.split('/')[-3:-2]

Thanks Paul, that’s the one I needed cheers.

@AlThePal, that’s python code, the question was about the Ignition-specific expression syntax.

Though you could use python code in an external function and call it from the expressions if you really want…

This is where I lean on the unique ability of objectScript() to efficiently execute a one-liner with access to an argument list. Like so:

objectScript("args[0].split('/')[-3:-2]", {Root Container.myStringProperty})

I was just about to post my question because I could not get it to work. Then I figured it out.

Custom Property holds my tag path

concat(“Trend - “, split({Root Container.UDT_Path},”/”)[1,0]," - “,split({Root Container.UDT_Path},”/")[3,0])