Author |
Message
|
ceteareth |
Posted: Mon Apr 21, 2014 1:45 am Post subject: TRIM multiple character singleton |
|
|
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 |
|
 |
kimbert |
Posted: Mon Apr 21, 2014 2:17 am Post subject: |
|
|
 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 |
|
 |
ceteareth |
Posted: Mon Apr 21, 2014 6:33 pm Post subject: |
|
|
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 |
|
 |
Esa |
Posted: Mon Apr 21, 2014 11:03 pm Post subject: |
|
|
 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 |
|
 |
Armageddon123 |
Posted: Mon Apr 21, 2014 11:42 pm Post subject: |
|
|
Acolyte
Joined: 11 Feb 2014 Posts: 61
|
|
Back to top |
|
 |
ceteareth |
Posted: Wed Apr 23, 2014 11:46 pm Post subject: |
|
|
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 |
|
 |
kimbert |
Posted: Thu Apr 24, 2014 12:16 am Post subject: |
|
|
 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 |
|
 |
Esa |
Posted: Thu Apr 24, 2014 12:19 am Post subject: |
|
|
 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 |
|
 |
ceteareth |
Posted: Thu Apr 24, 2014 12:59 am Post subject: |
|
|
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
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 |
|
 |
ceteareth |
Posted: Thu Apr 24, 2014 1:05 am Post subject: |
|
|
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 |
|
 |
|