String Manipulation

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

dsdoubt
Participant
Posts: 106
Joined: Sat Jul 15, 2006 12:17 am

String Manipulation

Post by dsdoubt »

Hi,

Input Data

ABC_xxx
ABC1_xxx
ABC2_xxx
yyy_ABC3_xxxx

I need to strip out all those characters to the left of _ that were before xxxx.
xxxx is just representation of string. So I need to strip out any char '...ABCn_'
n may or may not presetn. Some characters before ABC may or may not present.
An pointers?
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Re: String Manipulation

Post by ShaneMuir »

So you are only requiring the last bit of the field past the _? Ie the _xxxx will always be at the end? If so the easiest way would be to treat the underscore as a delimiter.
Perform a count of how many underscores there are in the field then use that number in the Field function to extract the last "column" as defined by your delimiter (which is '_'). You will probable need to add 1 to the number returned by the count. The syntax would be something like

Code: Select all

InputField['_',Count(InputField,'_')+1,1]
Unfortunately I don't have access to a system at present, so I can't check the syntax, but it would be something like that.
dsdoubt wrote:Hi,

Input Data

ABC_xxx
ABC1_xxx
ABC2_xxx
yyy_ABC3_xxxx

I need to strip out all those characters to the left of _ that were before xxxx.
xxxx is just representation of string. So I need to strip out any char '...ABCn_'
n may or may not presetn. Some characters before ABC may or may not present.
An pointers?
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Re: String Manipulation

Post by I_Server_Whale »

ShaneMuir wrote:The syntax would be something like

InputField['_',Count(InputField,'_')+1,1]

Unfortunately I don't have access to a system at present, so I can't check the syntax, but it would be something like that.
Yes. Shane's code will work. Here's the right syntax:

Code: Select all

Field(InLink.Col,'_',Count(InLink.Col,'_')+1,1)
Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Both syntaxes are correct (Shane's is called "delimited substring extraction") and will generate exactly the same object code.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dsdoubt
Participant
Posts: 106
Joined: Sat Jul 15, 2006 12:17 am

Post by dsdoubt »

Thanks for you inputs guys. I was extracting from Database, so manage to use database functions.

Code: Select all

 SUBSTR(field, INSTR(field, '_',INSTR(article_id, 'ABC'))+1)
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

ray.wurlod wrote:Both syntaxes are correct (Shane's is called "delimited substring extraction") and will generate exactly the same object code.
Thanks, Ray. Didn't know about "delimited substring extraction".
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
dsdoubt
Participant
Posts: 106
Joined: Sat Jul 15, 2006 12:17 am

Post by dsdoubt »

May I know what is the syntax of this.
Is it InputField[Delimiter,Start, End]?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Read about Field(). It works along the same lines.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

InputField[delimiter,start,count]

The delimiter asserts that you are dealing with a string (InputField) made up of zero or more substrings separated from each other by delimiter characters. For example "STRAWBERRY ICE CREAM" is a string containing 20 characters, or a string containing three words (substrings separated by " " characters), or a string containing four substrings delimited by "E", and so on.

When delimiter appears, the start and count integers refer not to individual characters but to delimited substrings. Thus, for example, if the variable Product contains "STRAWBERRY ICE CREAM" then the expression
Product["E",2,2] returns "RRY ICE CR" - as you can see, intervening delimiter characters are returned.

Finally, note that the third argument is a count of substrings to return, not the end position. In this respect your understanding was imprecise.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

Wonderful explaination. Thanks Ray!
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

If I would have answered, I would simply given InputField[ delimiter , start , count ]. Thats 'Ray'ish way.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It's known around here as The Full Wurlod. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Thats a good practice. Makes it clear to everyone. Ray, you should consider writing a book. It will be a great seller, and you can call it "DataStage for dummies" :wink:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hmmm... I'll let Ray respond to that.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

chulett wrote:Hmmm... I'll let Ray respond to that.
Not possible huh? Legal issues .... :?:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply