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 » TRIM multiple character singleton

Post new topic  Reply to topic
 TRIM multiple character singleton « View previous topic :: View next topic » 
Author Message
ceteareth
PostPosted: Mon Apr 21, 2014 1:45 am    Post subject: TRIM multiple character singleton Reply with quote

Acolyte

Joined: 12 Aug 2012
Posts: 51

Ive been spending time understanding how TRIM works on multiple character singletong.
I have read the wmbhelp of TRIM and tried it aswell but i am still puzzled by its behavior.

I cant figure out why the output is mgk. I understand that this maybe a noob question for most of you but i am just at a loss can you please help me further understand this function.

Quote:
An example of using a multiple character singleton is:

DECLARE input1 CHARACTER 'testmgktest';
SET OutputRoot.XMLNSC.Top.Out1 = TRIM( 'ste' FROM input1);

The preceding code produces the output message:
<Top><Out1>mgk</Out1></Top>


The example trims out 'ste' from 'testmgktest'. My expectation is that the result will still be 'testmgktest' since there is no sequence of string 'ste'.

thanks in advance.
Back to top
View user's profile Send private message
kimbert
PostPosted: Mon Apr 21, 2014 2:17 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

The first argument to TRIM is a set of characters that will be trimmed. Not a string.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
ceteareth
PostPosted: Mon Apr 21, 2014 6:33 pm    Post subject: Reply with quote

Acolyte

Joined: 12 Aug 2012
Posts: 51

Thanks for the response kimbert.

Sorry but i still cant understand how it was able to come up with "mgk"

my understanding on set of characters is that the sequence will be retained thus if we trim "ste" from a string then the function will look for a sequence of character "ste" in the string. if it found that there are 3 character "s", "t" and "e" one after the other in that sequence then it will remove that set of characters. thats how i understand it. in the string i cant find a "ste".

below is a couple of test that i did.

Code:

-- resulted [b]mgk[/b]
TRIM( 'tse' FROM input1);


Code:

-- resulted [b]mgk[/b]
TRIM( 'test' FROM input1);


Code:

-- resulted [b]estmgkte[/b]
TRIM( 'st' FROM input1);


I know that my understanding is wrong....i just want to undestand how this works. Thank you for all your patience
Back to top
View user's profile Send private message
Esa
PostPosted: Mon Apr 21, 2014 11:03 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

ceteareth wrote:


Code:

-- resulted [b]estmgkte[/b]
TRIM( 'st' FROM input1);


I know that my understanding is wrong....i just want to undestand how this works. Thank you for all your patience


Your example code keeps trimming letters 's' and 't' from left and right until it finds a letter that is not 's' or 't'.
Back to top
View user's profile Send private message
Armageddon123
PostPosted: Mon Apr 21, 2014 11:42 pm    Post subject: Reply with quote

Acolyte

Joined: 11 Feb 2014
Posts: 61

Please see this post, will be clear then.

http://www.mqseries.net/phpBB/viewtopic.php?p=294715&sid=9b4d767c22b9d06fb562f3827bffb370

this is the post where mgk has really added that example to the docs
Back to top
View user's profile Send private message
ceteareth
PostPosted: Wed Apr 23, 2014 11:46 pm    Post subject: Reply with quote

Acolyte

Joined: 12 Aug 2012
Posts: 51

Esa wrote:
ceteareth wrote:


Code:

-- resulted [b]estmgkte[/b]
TRIM( 'st' FROM input1);


I know that my understanding is wrong....i just want to undestand how this works. Thank you for all your patience


Your example code keeps trimming letters 's' and 't' from left and right until it finds a letter that is not 's' or 't'.


Thanks for the response Esa. Just a question tho.....if it is trimming letters 's' and 't' then why is the result 'estmgkte'? If it is trimming 's' and 't' then the result should be 'emgke'.
Back to top
View user's profile Send private message
kimbert
PostPosted: Thu Apr 24, 2014 12:16 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Check again - the result *was* 'emgke'!
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
Esa
PostPosted: Thu Apr 24, 2014 12:19 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

Trim 'testmgktest' with 'st:

Trimming from left:
1. First letter is 't' and it matches 'st'--> remove
2. Second letter is 'e' and it doesn't match 'st' --> stop trimming from left

Trimming from right:
1. First letter is 't' and it matches 'st' --> remove
2. Second letter is 's' and it matches 'st' --> remove
3. Third letter is 'e' and it doesn't match 'st' --> stop trimming.
Back to top
View user's profile Send private message
ceteareth
PostPosted: Thu Apr 24, 2014 12:59 am    Post subject: Reply with quote

Acolyte

Joined: 12 Aug 2012
Posts: 51

@kimbert
I tested this with Input Queue -> Database Node -> Output Queue.

Code:

CREATE DATABASE MODULE test_Database
   CREATE FUNCTION Main() RETURNS BOOLEAN
   BEGIN
      DECLARE RootRef REFERENCE TO Root;
      CALL test(RootRef);
      RETURN TRUE;
   END;
   
   CREATE FUNCTION test(IN rootRef REFERENCE)
   BEGIN
      DECLARE input1 CHARACTER 'testmgktest';
      DECLARE expr CHARACTER FIELDVALUE(rootRef.XMLNSC.Text);
      SET rootRef.XMLNSC.Text = TRIM( expr FROM input1);
   END;
END MODULE;


I sent message
Code:
<Text>st</Text>


Output was
Code:
<Text>estmgkte</Text>




Last edited by ceteareth on Thu Apr 24, 2014 1:09 am; edited 1 time in total
Back to top
View user's profile Send private message
ceteareth
PostPosted: Thu Apr 24, 2014 1:05 am    Post subject: Reply with quote

Acolyte

Joined: 12 Aug 2012
Posts: 51

Esa wrote:
Trim 'testmgktest' with 'st:

Trimming from left:
1. First letter is 't' and it matches 'st'--> remove
2. Second letter is 'e' and it doesn't match 'st' --> stop trimming from left

Trimming from right:
1. First letter is 't' and it matches 'st' --> remove
2. Second letter is 's' and it matches 'st' --> remove
3. Third letter is 'e' and it doesn't match 'st' --> stop trimming.


This makes sense Thanks Esa.

Thanks everyone
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » TRIM multiple character singleton
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.