ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » REPLACE and TRANSLATE

Post new topic  Reply to topic
 REPLACE and TRANSLATE « View previous topic :: View next topic » 
Author Message
kspranava
PostPosted: Mon Oct 24, 2005 8:46 pm    Post subject: REPLACE and TRANSLATE Reply with quote

Centurion

Joined: 27 Apr 2003
Posts: 124

Hi Gurus,

What is the difference between REPLACE and TRANSLATE functions?

Thanks & regards,
Pranava.
Back to top
View user's profile Send private message
javaforvivek
PostPosted: Mon Oct 24, 2005 11:34 pm    Post subject: Reply with quote

Master

Joined: 14 Jun 2002
Posts: 282
Location: Pune,India

Pranava,
Although the syntax for REPLACE and TRANSALTE is same,i.e.,
REPLACE/TRANSLATE (source,originalString, replacedBy);
REPLACE function will replace the originalString only when it will find it in the source. Whereas TRANSLATE will replace the originalString if it finds this in the source. If it doesn't find some part of orginalString in source, then it will delete the part which it found.
I will illustrate this with an example.
I have an input message:
<RootElement>
<Line1>This is a test</Line1>
<Line2>This is a test</Line2>
</RootElement>

I will now show you, how the REPLACE and TRANSLATE work in different cases: The rest of the code will remain same, only the call to the function will alter:
Code 1:
Code:

DECLARE line1,line2 CHARACTER;
SET line1 = InputRoot.XML.RootElement.Line1;
SET line1 = REPLACE (line1,'t','y');
SET line2 = InputRoot.XML.RootElement.Line2;
SET line2 = TRANSLATE (line2,'t','y');
CREATE FIELD OutputRoot.XML.Message;
CREATE FIRSTCHILD OF OutputRoot.XML.Message NAME 'Line1' VALUE line1;
CREATE LASTCHILD OF OutputRoot.XML.Message NAME 'Line2' VALUE line2;

will give you output as:
<Message>
<Line1>This is a yesy</Line1>
<Line2>This is a yesy</Line2>
</Message>

Code 2:
Code:

SET line1 = REPLACE (line1,'tt','y');
SET line2 = TRANSLATE (line2,'tt','y');

will give me output as:
<Message>
<Line1>This is a test</Line1>
<Line2>This is a yesy</Line2>
</Message>

Code3:
Code:

SET line1 = REPLACE (line1,'zt','y');
SET line2 = TRANSLATE (line2,'zt','y');

will give me output as:
<Message>
<Line1>This is a test</Line1>
<Line2>This is a es</Line2>
</Message>

You can go on with various combinations to illustrate it further.
_________________
Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » REPLACE and TRANSLATE
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.