Remove a substring in 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

prasson_ibm
Premium Member
Premium Member
Posts: 536
Joined: Thu Oct 11, 2007 1:48 am
Location: Bangalore

Post by prasson_ibm »

I think convert function will work here.Test this function and let us know.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Ereplace() should work. It performs substring replacement. Simply replace the unwanted substring with "".

Convert() is good if the characters to be removed do not occur anywhere else in the data.

Otherwise you'll need a mix of Index() function and substring operators.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hi_manoj
Participant
Posts: 56
Joined: Sat Aug 13, 2011 2:00 pm
Location: BLR

Post by hi_manoj »

Thanks Ray and Prasson,

You are correct Ray convert work basically character replacement function not word. So can not be a option for my case.

Ereplace can be but the job is a parallel job and is already running in production, the changes I am doing is a patch to the code and as you know ereplace will not work if the job is parallel.

As per my understanding ereplace works if the transformer is Basic Transformer, if it parallel then I think it will not work. Let me know if I am wrong.

Regards
Manoj
Manoj
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

In version 9.1.2 Ereplace() is available for parallel jobs. For versions 8.x and earlier you can use the pxEreplace() function provided here on DSXchange.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hi_manoj
Participant
Posts: 56
Joined: Sat Aug 13, 2011 2:00 pm
Location: BLR

Post by hi_manoj »

Hi

Not sure how it is, but convert seems t be working. I have tried to replace replace string with "" and I can see the changes, looks like correct replacement is happening.
.old.
old
.oldold
old.
old.old

I will keep this issue open for few more days, because I am going to implement this for 27 files.

Thanks for your response.

Regards
Manoj
Manoj
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

As ray mentioned
ray.wurlod wrote:Convert() is good if the characters to be removed do not occur anywhere else in the data.
You will have to make sure that characters to be removed do not occur anywhere else in the data, else you might not get the correct result.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I would be extremely leery of using Convert() for this. However, when you said "I have to remove some part of the string" you never mentioned what part you need to remove. Details like that could help allay those fears.
-craig

"You can never have too many knives" -- Logan Nine Fingers
hi_manoj
Participant
Posts: 56
Joined: Sat Aug 13, 2011 2:00 pm
Location: BLR

Post by hi_manoj »

Sorry for a late response. I was busy with some production task.
Yes, you Guru's are correct and I have also came across some example. So Convert is not going to help me.

I think I have to go for the parallel routine pxEreplace(), but which one is question. Can I get a link to the correct version among DSguru2B and Phil Hibbs

Regards
Manoj
Manoj
hi_manoj
Participant
Posts: 56
Joined: Sat Aug 13, 2011 2:00 pm
Location: BLR

Post by hi_manoj »

Hi,

I came to know that the sub-string OLD will appear at the end of the string and it will come with . append to it at front (.OLD) but it can be appear one time or more time.

giving you some example
06053FOL7.OLD => 06053FOL7
06053FDL7.X.OLD => 06053FDL7.X
06053FLD7.X.OLD.OLD => 06053FLD7.X
06053FAAOLD7OLD => leave as is
378272AD0.OLD.OLD =>378272AD0

if there is any way I can remove the repetition of .OLD their I will have one .OLD at that is at end of the string then I can do it with function Index and Left.

Any Idea how can I do suppress the repetition.
Manoj
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can use looping in the Transformer.

Prefer Phil Hibbs' most recent version of pxEreplace() function. Or upgrade to version 9.1.2 and get an inbuilt Ereplace() function in the parallel Transformer.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hi_manoj
Participant
Posts: 56
Joined: Sat Aug 13, 2011 2:00 pm
Location: BLR

Post by hi_manoj »

Hi All, Thanks for your valuable input.
I think I have resolve this, after doing a long effort I find a simple solution. As I have mention that .OLD will be at the end of the string and can be more then once, so with help of field function I fix this issue.

Field(UpCase(input.column_1),".OLD",1).

Although I have submitted this for review but if you fin any issue please let me know.

Ray,

Regarding Transformer I am able to get the value correct but the records are repeating if .OLD is repating in the string. Issue is how I will retain the value in the loop.

I am also trying to implement the pxEreplace() but it will be for my learning

Regards
Manoj
Manoj
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The Field() function only supports a single character as the delimiter:

"delimiter evaluates to any character, including field mark, value mark, and subvalue marks. It delimits the start and end of the substring. If delimiter evaluates to more than one character, only the first character is used. Delimiters are not returned with the substring. "
-craig

"You can never have too many knives" -- Logan Nine Fingers
hi_manoj
Participant
Posts: 56
Joined: Sat Aug 13, 2011 2:00 pm
Location: BLR

Post by hi_manoj »

According to you if your input value is 06053FDL7.X.OLD then derivation
Field(UpCase(06053FDL7.X.OLD),".OLD",1) should be 06053FDL7 (as you have mention) but I am getting value 06053FDL7.X as my output and this is what I am excepting

Let me know if any issue with this.
Manoj
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry but that's not according to me but rather according to the documentation. If you feel that's working for you, that's fine, but don't be surprised if in the future you install a fixpack and it no longer 'works'. And hopefully the only period in the string is in front of "OLD".

Just say'n.
-craig

"You can never have too many knives" -- Logan Nine Fingers
hi_manoj
Participant
Posts: 56
Joined: Sat Aug 13, 2011 2:00 pm
Location: BLR

Post by hi_manoj »

It was not intention to say, sorry for that.
No the period can happen any where in the string, like I have mention below.

06053FDL7.X.OLD -- period is there in font of X and OLD. And the output should be 06053FDL7.X and it is happening.

Please check my last post
Manoj
Post Reply