Page 1 of 1

replace function

Posted: Mon Aug 25, 2008 7:00 pm
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

Use Multiple Functions to Resolve this

Posted: Mon Aug 25, 2008 8:13 pm
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


Posted: Mon Aug 25, 2008 8:16 pm
by ray.wurlod
Search this forum for an EReplace() function written by one of our contributors.

Replace a pattern in string

Posted: Tue Mar 12, 2013 2:37 am
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

Re: Replace a pattern in string

Posted: Tue Mar 12, 2013 2:43 am
by raju4u
can u give one example how do u want to replace..

Posted: Tue Mar 12, 2013 3:24 pm
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++

Posted: Tue Mar 12, 2013 5:33 pm
by jhmckeever
You probably want to take a look at <a href="viewtopic.php?t=106358&highlight=PXEReplace">this post</a>.