replace function

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
pavan_test
Premium Member
Premium Member
Posts: 263
Joined: Fri Sep 23, 2005 6:49 am

replace function

Post by pavan_test »

Hi All,

Can anyone please suggest me if there is any replace function in data stage. i could not find it in help. can anyone please suggest me how do i use it in data stage.

Thanks
Mark
Django
Premium Member
Premium Member
Posts: 20
Joined: Fri Apr 18, 2008 12:16 am

Use Multiple Functions to Resolve this

Post by Django »

Code: Select all

Left(SourceString, index(SourceString,FindString) - 1) will give the left part of the string 

Right(SourceString, Len(SourceString) - (index(SourceString,FindString) + Len (FindString) - 1 )) will give the Right part of the sring 

When you combine these both using a : operator with your new string you'll get the desired result

Eg. 

SourceString = 'SuperSoulExistsEveryWhere'
FindString = Exists
AddString = OverSees

Left ( 'SuperSoulExistsEveryWhere', 10 - 1) = SuperSoul
Right ('SuperSoulExistsEveryWhere', 25 - ( 10 + 6 - 1) ) = EveryWhere

Ans = SuperSoul : 'OverSees' : EveryWhere

Django
If a simple dsx project requires such intelligence how much more is required to create this Cosmic System. Who dares to say there is no intelligence behind this creation i.e. no GOD .....
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Search this forum for an EReplace() function written by one of our contributors.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
saintankit
Participant
Posts: 1
Joined: Tue Mar 12, 2013 2:33 am
Location: india

Replace a pattern in string

Post by saintankit »

Below is the code of Datastage routine to Replace a pattern in string

Input_String = Arg1
From_String = Arg2
To_String = Arg3

Len_From_String = Len(From_String)
Diff_Len = Len(To_String) - Len(From_String)
Loop_String = Input_String

For i = 1 To Count(Loop_String, From_String)
Loc_old = Index(Loop_String, From_String,i)

If (i<>1) Then Loc = Loc_old + (Diff_Len * (i-1)) Else Loc = Loc_old
Input_String = Left(Input_String, Loc-1) : To_String : Right(Input_String,Len(Input_String) - Loc - Len_From_String + 1)
Next
Ans = Input_String
raju4u
Participant
Posts: 56
Joined: Thu Dec 13, 2007 12:30 am

Re: Replace a pattern in string

Post by raju4u »

can u give one example how do u want to replace..
N R REDDY
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard, saintankit. Unfortunately a server routine will not serve the original request, which is in a parallel job.

For parallel jobs the routine must be written in C++
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 »

You probably want to take a look at <a href="viewtopic.php?t=106358&highlight=PXEReplace">this post</a>.
<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>
Post Reply