Author |
Message
|
Esa |
Posted: Thu Mar 29, 2012 1:27 am Post subject: character string to list |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Code: |
DECLARE foo CHAR 'one;two,three';
DECLARE myList LIST CAST(foo AS LIST DELIMITER ';') |
This type of cast is unfortunately not supported.
Which would be the best performing way to get a list from a string in ESQL (if wrapping a java method is not applicable), the traditional brute force approach with POSITIONs and SUBSTRINGs, or casting the string to BLOB and parsing it into a little message tree with MRM? Or something I have overlooked? |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Mar 29, 2012 1:58 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Well, you could review again the functions available in ESQL and see if they've snuck one in. An overly quick glance on my part doesn't show one, but I'm sure I was hasty.
You could also misuse EVALUATE, maybe. |
|
Back to top |
|
 |
Esa |
Posted: Thu Mar 29, 2012 2:57 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
My example is a bit incorrect, because LIST is actually not a real datatype but more like an interface. So I correct it like this:
Code: |
DECLARE foo CHAR 'one;two,three';
DECLARE ref.foolist.foo[] = CAST(foo AS LIST DELIMITER ';') |
or
Code: |
DECLARE foo CHAR 'one;two,three';
DECLARE ref.foolist.foo[] = EXPLODE(foo DELIMITER ';') |
Neither of these, of course, exist in ESQL. But it would be nice if one of them did. Not very probable to get this through with an enhancement request because you can always write ten or twenty lines of code to explode a string into an iterable entity. |
|
Back to top |
|
 |
Esa |
Posted: Thu Mar 29, 2012 5:11 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Well, I decided to take the brute force approach.
But i must say that I managed to develop a really nice and efective little 15-line iterator function that even takes care of empty strings between delimiters.
Feels like having invented a wheel! I feel like a king
This is why ESQL lacks a string tokenizer! It would just make the work more boring and productive  |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Mar 29, 2012 5:24 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Esa wrote: |
This is why ESQL lacks a string tokenizer! It would just make the work more boring and productive  |
IMHO very few 'young' coders understand was tokenizer parsing is all about.
I may even still have the code somewhere around for one I wrote in PDP-11 Macro around 1977/78.
 _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
Esa |
Posted: Thu Mar 29, 2012 5:31 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
smdavies99 wrote: |
IMHO very few 'young' coders understand was tokenizer parsing is all about.
|
Das glaube me too
It's because they have it in java schon fertig. Just plug and spielen! |
|
Back to top |
|
 |
th61678 |
Posted: Thu Sep 12, 2013 5:41 pm Post subject: Still have the 15 tokenizer around? |
|
|
Newbie
Joined: 12 Sep 2013 Posts: 1
|
I've come across the same situation and could really make use of a tokenizer to turn a CHAR into a list. If you still have those 15 line iterator function I would love to take look...save me some time.
Thanks! |
|
Back to top |
|
 |
|