Page 1 of 1

Last Occurrence in String

Posted: Thu May 15, 2014 9:57 am
by eli.nawas_AUS
Is there a way to find the last occurrence in a string of a character?

For instance, if I want to get the file part of a file path (/a/b/c/file.txt), how can I extract that?

Posted: Thu May 15, 2014 10:06 am
by ArndW
I assume you don't want to do this via regex but in a transform stage, correct? The following derivation

Code: Select all

FIELD(In.StringColumn,'/',DCOUNT(In.StringColumn,'/'))
will give you the last substring delimited by a '/'.

Posted: Thu May 15, 2014 10:55 am
by chulett
Just to confirm, you specifically mean the last 'occurance' in a delimited string, yes? That was your 'for instance', just wanted to make sure that would cover all of the bases.

Posted: Thu May 15, 2014 2:45 pm
by ray.wurlod
You can use the UNIX command basename for this particular task (getting the file name from a pathname).