|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
String Tokenizer Function in ESQL |
« View previous topic :: View next topic » |
Author |
Message
|
DanielSonFocus |
Posted: Wed Jun 08, 2005 6:07 pm Post subject: String Tokenizer Function in ESQL |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
Given this from InputRoot:
<xml>: 1: 2: 3: 4: 5: 6: 7:<xml>
i'd like to create this in my OutputRoot:
<xml>
<a>1</a>
<b>2</b>
<c>3</c>
<d>4</d>
<e>5</e>
<f>6</f>
<g>7</g>
</xml>
i'd like some String Tokenizing function similar to java.lang.StringTokenizer.. anyone know where i can find this? |
|
Back to top |
|
 |
martinrydman |
Posted: Wed Jun 08, 2005 10:52 pm Post subject: |
|
|
 Centurion
Joined: 30 Jan 2004 Posts: 139 Location: Gothenburg, Sweden
|
No, but I've put together a Split function which is rough but does the job. Looks like this:
Code: |
/*
========================================================================================
PROCEDURE Split
========================================================================================
Splits S on Delim into an array in Env (Environment.Split.Array[])
Removes Environment.Split before refilling it
*/
CREATE PROCEDURE Split (IN S CHARACTER, IN Env REFERENCE, IN Delim CHARACTER)
BEGIN
DECLARE P INTEGER;
DECLARE Idx INTEGER 1;
SET Env.Split = NULL;
REPEAT
SET P = POSITION(Delim IN S);
IF P = 0 THEN
SET Env.Split.Array[Idx] = S;
ELSE
SET Env.Split.Array[Idx] = LEFT(S, P - 1);
SET S = SUBSTRING(S FROM P + LENGTH(Delim));
SET Idx = Idx + 1;
END IF;
UNTIL P = 0
END REPEAT;
END;
|
In your case, it should work. Only thing to note is that you have both a leading and trailing ':'.
Also, note that Env is passed as a parameter. This is because Split resides in separate routine library. If you put Split into your COMPUTE MODULE, you won't need to pass Environment, since it would then be within scope.
/Martin |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Jun 09, 2005 3:24 am Post subject: Re: String Tokenizer Function in ESQL |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
DanielSonFocus wrote: |
<xml>: 1: 2: 3: 4: 5: 6: 7:<xml> |
I don't think that's valid XML.
You could certainly model it in MRM, though, then you wouldn't need to play around with position and substring. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
DanielSonFocus |
Posted: Thu Jun 09, 2005 1:01 pm Post subject: |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
wow thanks for the input Martin... function works great!  |
|
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
|
|
|
|