Last Occurrence in String

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
eli.nawas_AUS
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 15, 2014 9:14 am

Last Occurrence in String

Post 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?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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 '/'.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can use the UNIX command basename for this particular task (getting the file name from a pathname).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply