|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Substring before newline |
« View previous topic :: View next topic » |
Author |
Message
|
wmqstankela |
Posted: Wed Apr 24, 2019 2:22 am Post subject: Substring before newline |
|
|
Voyager
Joined: 29 Feb 2016 Posts: 94
|
Hi all,
I'm using iib V10 and I exposed some REST service on it. I have input parameter which is char and sometimes clients send me string with newline in it. i want to substring everything before newline.
I've tried this, but it doesn't work
Code: |
DECLARE CR CHAR CAST(CAST('X''0A''' AS BLOB) AS CHAR CCSID InputRoot.Properties.CodedCharSetId);
DECLARE temp CHAR;
SET temp = SUBSTRING(InputRoot.JSON.Data.beneCustName BEFORE CR);
|
or
Code: |
SET temp = SUBSTRING(InputRoot.JSON.Data.beneCustName BEFORE '
');
|
Can someone help with this? |
|
Back to top |
|
 |
timber |
Posted: Wed Apr 24, 2019 3:27 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
|
Back to top |
|
 |
rekarm01 |
Posted: Wed Apr 24, 2019 5:33 pm Post subject: Re: Substring before newline |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
wmqstankela wrote: |
I have input parameter which is char and sometimes clients send me string with newline in it. |
Unparsed JSON strings should not have literal control characters, including any end-of-line characters. Instead they should have escape sequences, like "\n" for line feed (LF), and "\r" for carriage return (CR). What does the unparsed JSON look like?
wmqstankela wrote: |
I've tried this, but it doesn't work |
"doesn't work" is a bit vague. A usertrace might describe more completely what it does do.
wmqstankela wrote: |
Code: |
DECLARE CR CHAR CAST(CAST('X''0A''' AS BLOB) AS CHAR CCSID InputRoot.Properties.CodedCharSetId); |
|
The variable name for the converted BLOB literal (X'0A') would usually be "LF", not "CR". Regardless, the BLOB does not come from the input message, so it should not depend on the input ccsid. Since it is hard-coded, the ccsid can be, too; any ASCII-based ccsid will do, such as 367 (US-ASCII), 819 (ISO-8859-1), or 1208 (UTF-8):
Code: |
DECLARE LF CHAR CAST(X'0A' AS CHAR CCSID 819); |
Of course, it would still help to know what end-of-line character sequence to expect in the input. Is it just an LF, or could it be CR+LF, or maybe something else?
wmqstankela wrote: |
Code: |
SET temp = SUBSTRING(InputRoot.JSON.Data.beneCustName BEFORE '
'); |
|
Embedding a literal end-of-line sequence in a CHAR string is unreliable. That is why developers make the extra effort to CAST BLOB literals to CHAR in the first place. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|