Author |
Message
|
mpong |
Posted: Thu Nov 07, 2013 3:44 am Post subject: Understanding Trim Function |
|
|
Disciple
Joined: 22 Jan 2010 Posts: 164
|
Hi All,
I am using Data pattern to receive below msg.
"text1" "text2" "text3"
After i receive each element in compute node, i want to trim leading and trailing double quotation marks so i used the below code and it works but i don't understand how exactly it works.
SET Text = TRIM('"' FROM (InputRoot.MRM.text1)); it trims only on the left side not both side.
Result : Text = text1"
but when i use trim function twice i get the result as expected
SET Text = TRIM('"' FROM TRIM(InputRoot.MRM.text1));
Result : Text = text1
Can you pls explain me, I dont understand how exactly the inner trim function helps.
EDIT by exerk: Moving this to the Broker forum. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Nov 07, 2013 3:57 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You shouldn't be using Data Patterns for this.
You shouldn't be using MRM for this.
You're trying to parse a CSV file the hard way.
Go back to the product samples and your training material and start over.
If you're on WMB v8 or 9 use the DFDL parser and use the predefined models for CSV files. If you're not on v8 or v9, use the MRM samples for CSV files.
The TRIM function does exactly what it's documented to do.
The TRANSLATE function does exactly what it's documented to do.
They are different functions. |
|
Back to top |
|
 |
dogorsy |
Posted: Thu Nov 07, 2013 4:16 am Post subject: Re: Understanding Trim Function |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
I don't think this can work:
mpong wrote: |
SET Text = TRIM('"' FROM TRIM(InputRoot.MRM.text1));
|
As the inner TRIM would trim the default character, i.e. spaces and not the double quotes as you claim. So your code is suspect.
Or, your InputRoot.MRM.text1 is in fact '"text1" ', i.e you are receiving the string "text1" followed by a space. In wich case only one TRIM will not work, as the " is followed by a space. In that case, the inner trim is removing the spaces at the end, and then the next trim removes the double quotes.
Whichever way, if you run a user trace and read it, you will find what the problem is and will help you to understand the Trim function |
|
Back to top |
|
 |
mpong |
Posted: Thu Nov 07, 2013 10:09 pm Post subject: |
|
|
Disciple
Joined: 22 Jan 2010 Posts: 164
|
Hi,
This is not a CSV file, input from the source file is as below:
"aaaaaaa" "bbbbb" "cccccc" "dddd"
and I use MRM message set using the data patteren "[^"]*" to fetch each element and it works fine.
SET Element1 = TRIM('"' FROM TRIM(InputRoot.MRM.text1)); also gives me the correct output. |
|
Back to top |
|
 |
Esa |
Posted: Thu Nov 07, 2013 10:41 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
mpong wrote: |
This is not a CSV file, input from the source file is as below:
"aaaaaaa" "bbbbb" "cccccc" "dddd"
and I use MRM message set using the data patteren "[^"]*" to fetch each element and it works fine.
SET Element1 = TRIM('"' FROM TRIM(InputRoot.MRM.text1)); also gives me the correct output. |
Yes, because text1 contains '"aaaaaaa" '.
now I see that dogorsy already told you that. |
|
Back to top |
|
 |
dogorsy |
Posted: Fri Nov 08, 2013 12:04 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
mpong wrote: |
SET Element1 = TRIM('"' FROM TRIM(InputRoot.MRM.text1)); also gives me the correct output. |
I have already explained why, and also suggested you get a user trace, look at it and understand the TRIM function. |
|
Back to top |
|
 |
mpong |
Posted: Fri Nov 08, 2013 4:12 am Post subject: |
|
|
Disciple
Joined: 22 Jan 2010 Posts: 164
|
Hi dogorsy, got it thanks  |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Nov 08, 2013 8:09 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
mpong wrote: |
Hi,
This is not a CSV file, input from the source file is as below:
"aaaaaaa" "bbbbb" "cccccc" "dddd"
and I use MRM message set using the data patteren "[^"]*" to fetch each element and it works fine.
SET Element1 = TRIM('"' FROM TRIM(InputRoot.MRM.text1)); also gives me the correct output. |
Yes, it is a CSV file.
It's just the "C" is actually a "space", not a "comma".
The sooner you accept that, the sooner you will stop using data patterns and start improving the format of your flow. |
|
Back to top |
|
 |
|