Extract substring from a string

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
nasimul
Participant
Posts: 37
Joined: Wed Jan 25, 2006 1:38 am

Extract substring from a string

Post by nasimul »

Hi,
I need to extract a substring from a string.
For example:

'FAS960C' should be converted to 'FAS960'
'FAS960HC' should be converted to 'FAS960'

Requirement: Once there is a transition from numeric to character, then we are going to stop the search and provide result till that poistion.

Please help how to do it.

Thanks,
Nasimul
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Nasimul,

that is an interesting question - I can't think of an easy way to do this in PX as there are no regular expression functions. The cheap way (which I wouldn't recommend) is to call a BASIC transform where this type of pattern matching can be done easily.

Can you specify the rule differently, i.e. "everything to the left of the first '9' in the string"? What is the maximum length of the string? One could use stagevars to

Code: Select all

IF INDEX(In.String,"0")THEN INDEX(In.String,"0") ELSE 9999
IF INDEX(In.String,"1")THEN INDEX(In.String,"1") ELSE 9999
IF INDEX(In.String,"2")THEN INDEX(In.String,"2") ELSE 9999
IF INDEX(In.String,"3")THEN INDEX(In.String,"3") ELSE 9999
IF INDEX(In.String,"4")THEN INDEX(In.String,"4") ELSE 9999
IF INDEX(In.String,"5")THEN INDEX(In.String,"5") ELSE 9999
IF INDEX(In.String,"6")THEN INDEX(In.String,"6") ELSE 9999
IF INDEX(In.String,"7")THEN INDEX(In.String,"7") ELSE 9999
IF INDEX(In.String,"8")THEN INDEX(In.String,"8") ELSE 9999
IF INDEX(In.String,"9")THEN INDEX(In.String,"9") ELSE 9999

FirstNumPos = MIN(MIN(MIN(Pos0,Pos1),MIN(Pos2,Pos3)),MIN(Pos4,Pos5))...
This is rather inefficient and if you have c++ skills then this would be a great place to write a buildop.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You could use an External Filter stage and process your string through, say, awk. This can handle regular expressions.

In BASIC you could use MatchField() functions.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

ArndW wrote:that is an interesting question - I can't think of an easy way to do this in PX as there are no regular expression functions.
Although you could add your own regular expression support using the C-source I posted <a href="viewtopic.php?t=107882"> here</a>.

J.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

:oops: ... and I'd even added that to my Favorites!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
nasimul
Participant
Posts: 37
Joined: Wed Jan 25, 2006 1:38 am

Post by nasimul »

Thanks for the suggestion of using External Filter stage. But a quick question: Wouldn't it be a hit on performance?
nasimul
Participant
Posts: 37
Joined: Wed Jan 25, 2006 1:38 am

Post by nasimul »

Thanks for the suggestion of using External Filter stage. But a quick question: Wouldn't it be a hit on performance?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What do you mean by "performance" in an ETL context? Isn't being able to perform a task better than not being able to do so?
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