Case Insensitive Replace

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

Post Reply
DS_SUPPORT
Premium Member
Premium Member
Posts: 232
Joined: Fri Aug 04, 2006 1:20 am
Location: Bangalore

Case Insensitive Replace

Post by DS_SUPPORT »

Gurus,

Is there any way to replace a set of characters, case INsensitively.

For ex,

Code: Select all

  My input can be 

     Hash_CRC_TABLE1 
     HASH_crc_Table2

My output should be 

     Hash_TST_TABLE1 
     HASH_TST_Table2
I can convert the input to uppercase or lower case , and replace the string, but I want to maintain the case for other letters.

In the above ex, i want to replace the word "CRC" to 'TST" , without changing the other letters. Is there anyway to do it in server jobs or in server routines?
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Re: Case Insensitive Replace

Post by sachin1 »

EREPLACE may help
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

In a brute force sense, yes. You'd need to run one EReplace for each case combination you'd want to replace: "CRC", "crc", "Crc", "CrC", etc.

I'm not aware of any "case insensitive" mechanism, perhaps others are. Question - is the text you want to replace always delimited as your example shows? If so, you could snip that piece out, upcase and replace, then put the piece back.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DS_SUPPORT
Premium Member
Premium Member
Posts: 232
Joined: Fri Aug 04, 2006 1:20 am
Location: Bangalore

Post by DS_SUPPORT »

No , the input might not be same format always, I just give that example for a better clarity.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Please clarify what you are asking. It it a case-insensitive search and replace always with the same constant value or do you wish (as in your example) to preserve the casing when you undertake the replacement?

I think the only solution to the latter is a custom routine. None of the "out of the box" routines can do it.

Code: Select all

FUNCTION CaseReplace(OriginalString,ReplacementString,SourceString)
* Case-insensitive replacement
If Len(ReplacementString) <> Len(OriginalString)
Then
   Call DSTransformError("Replacement string must be same length as source string", "CaseReplace")
   @SYSTEM.SET = -1
   Return(@NULL)
End
Temp1 = Upcase(OriginalString)
Temp2 = Upcase(ReplacementString)
Temp3 = Ereplace(SourceString,Temp1,Temp2,-1,0)
ChCount = Len(SourceString)
LittleA = Seq("a")
LittleZ = Seq("z")
Ans = ""
For X = 1 To ChCount
   CodePoint =  Seq(SourceString[X,1])
   If CodePoint >= LittleA And CodePoint <= LittleZ
   Then
      Ans := DownCase(Temp3[X,1])
   End
   Else
      Ans := Temp3[X,1]
   End
Next X
Return(Ans)
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... not sure I would have thought of that technique. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DS_SUPPORT
Premium Member
Premium Member
Posts: 232
Joined: Fri Aug 04, 2006 1:20 am
Location: Bangalore

Post by DS_SUPPORT »

Excellent Ray, Cool and Superb Solution. Thanks a lot.

I have to add UpCase , for the source string also, then only i am getting the desired output.

Code: Select all

Temp3 = Ereplace(UpCase(SourceString),Temp1,Temp2,-1,0) 
Post Reply