extract variable from delimited string of words

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
Sgiri1
Participant
Posts: 43
Joined: Sat Nov 08, 2008 10:58 pm
Location: Tambaram

extract variable from delimited string of words

Post by Sgiri1 »

hi,

how to extract the valid value of the delimited string.

example: from the string of words below i should fetch he value of 'VARIABLE' which is 12345

this is an;VARIABLE=12345;example for my requirement

the strings are repetitive and i may receive NULL values for the VARIABLE. in such a case i must fetch the first valid value.

example:this is an;VARIABLE=;example for my requirement this is an;VARIABLE=;example for my requirement this is an;VARIABLE=2168;example for my requirement this is an;VARIABLE=12345;example for my requirement

i should extract the value 2168 from the string of words above.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Fairly simple in a Server routine:

Loop through the string using Field() with ";" as the delimiter,
..Use Index() to see if "VARIABLE=" is in the token,
....If yes, Field() again with "=" as the delimiterm take 2nd field,
..Stop when first non-null value found or you run out of tokens.

Sorry, but not sure what the PX secret would be.
-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 »

Using a BASIC Transformer stage

Code: Select all

If Index(InLink.TheString,"VARIABLE=",1) Then MatchField(InLink.TheString,"0X'VARIABLE='0N0X",3) Else @NULL
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Interesting. So, no equivalent in the PX world?
-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 »

Can't think of one that will reliably handle an arbitrary length numeric value. Other than a custom parallel routine, of course.

But the BASIC Transformer is a parallel job solution.
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