Author |
Message
|
nukalas2010 |
Posted: Tue Sep 27, 2011 10:40 pm Post subject: Split String in JAVA COMPUTE NODE |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
Hi All,
can anyone kindly let me know how to separate the string in java which is as follows combined with "~" and ":"
BLORE~Bangalore Service:CHENN~Chennai Services:ND~New Delhi:USA~United States of America:
I want to generate the output as below
Quote: |
<Code>BLORE</Code>
<Name>Bangalore Service</Name>
<Code>CHENN</Code>
<Name>Chennai Services</Name>
<Code>USA</Code>
<Name>United States of America</Name> |
I posted this because of high priority, it will be very helpful if anyone already works on this.. please dont mind |
|
Back to top |
|
 |
kevinobyrne |
Posted: Wed Sep 28, 2011 1:19 am Post subject: |
|
|
 Voyager
Joined: 17 Jul 2007 Posts: 83 Location: Ireland
|
What's wrong with using a message set and esql/mapping node? |
|
Back to top |
|
 |
saurabh867 |
Posted: Wed Sep 28, 2011 1:21 am Post subject: |
|
|
Voyager
Joined: 13 Jun 2010 Posts: 78
|
As suggested, you should try creating a message set for this.
For Java: Read about StringTokenizer. |
|
Back to top |
|
 |
anandsitha |
Posted: Wed Sep 28, 2011 3:08 am Post subject: |
|
|
Acolyte
Joined: 26 Jul 2011 Posts: 59
|
Hi nukalas2010-
Here is your java code to complete your task. I have used stringtokenizer.
Code: |
import java.util.*;
public class SplitStringSitha {
public static void main(String args[])
{
StringTokenizer st1 = new StringTokenizer("BLORE~Bangalore Service:CHENN~Chennai Services:ND~New Delhi:USA~United States of America:", "~:");
String str="";
int i = 1;
while(st1.hasMoreTokens())
{
if ((i%2)==0)
{
str = str+ "<Name>" + st1.nextToken() + "</Name>";
}
else
{
str = str + "<Code>" + st1.nextToken() + "</Code>";
}
i = i+1;
}
System.out.println(str);
}
}
|
Regards
Sithanandam.V |
|
Back to top |
|
 |
nukalas2010 |
Posted: Wed Sep 28, 2011 3:39 am Post subject: |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
Hi All,
thanks for yr responsding.. I had done by using the Split function in java.. and its working fine
My code looks like below..
Quote: |
String sCodes[] = sPurCode.split("\\:");
for(int i=0; i<sCodes.length; i++) {
String sNameValue[] = sCodes[i].split("\\~"); then mapping as per my requirement.. |
 |
|
Back to top |
|
 |
kevinobyrne |
Posted: Wed Sep 28, 2011 4:03 am Post subject: |
|
|
 Voyager
Joined: 17 Jul 2007 Posts: 83 Location: Ireland
|
Are you using websphere message broker? I ask because you don't appear to be using the fundamental capabilities of broker. I could assume you were using the MQ API to read and write messages and manipulating them with your java code. |
|
Back to top |
|
 |
zpat |
Posted: Wed Sep 28, 2011 4:49 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
There is an unfortunate tendency for new "WMB developers" to fail to use WMB in the way it is intended, but simply to host their Java code.
As well as some training, it is vital to have an experienced WMB developer/architect to mentor new developers.
Otherwise this sort of thing only comes to light when they can't make it work. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Sep 28, 2011 4:55 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
zpat wrote: |
Otherwise this sort of thing only comes to light when they can't make it work. |
Or when someone asks why WMB is performing so badly & out trots loads of custom reinvented wheels like this.
zpat wrote: |
There is an unfortunate tendency for new "WMB developers" to fail to use WMB in the way it is intended, but simply to host their Java code |
Though this is the first time I can remember where someone's tried to use Java not to extend WMB in some weird & unfortunate way, but to actually hand-craft a principle function of WMB (which IBM is being paid hansomly to provide). _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Sep 28, 2011 4:59 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
anandsitha wrote: |
Here is your java code to complete your task. |
Why provide this code? Why not point out this is a fool's errand and is much better performed using WMB's facilities? There's no reason to write this in Java when you're sitting inside a giant parsing engine.
(It's interesting the OP didn't even use Java's tokenization as you suggested, but is slogging through with string functions)
What do you expect the OP to do when someone hands over a SWIFT message to parse? Or when sitting in an interview someone asks "so tell me about the most complex message you've had to parse" and they launch off into an explaination of some Java rather than the message set they built? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Gaya3 |
Posted: Wed Sep 28, 2011 5:45 am Post subject: |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
i guess IBM has to come up with one more tool to erradicate this kind of design and code issues  _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
Esa |
Posted: Thu Sep 29, 2011 1:35 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Well, well, the atmosphere on this forum seems to have grown quite a bit harder during my summer vacation. This is, of course, part of a global trend and happening on all discussion forums around the world. Newbies and java, immigrants and Islam, nutrition gurus and their low carbon food, liberals against fundamentalists on all possible areas of life including collecting stamps, I suppose...
I must have my say. Java is a perfect tool to use with Message Broker. The only problem is that you will have to have an at least almost fully functional brain and at least five years of experience with both Message Broker and java to succeed. And have a good mentor.This is why we are facing so much bad Message Broker java design these days. At least four years must pass before the situation starts to get better. If all that bad java has not damaged Message Brokers reputation for good by then .
There is nothing wrong in using message sets, that is the way to do it even if you are using java for transforming the messages. But I would not be so categorically against string manipulation. There are cases when you simply have to use it, for example if you cannot be sure that the input message is valid and you still have to parse it. You know, Message Broker is not the only platform where bad design happens.
One of the strengths of Message Broker is that you can use it to handle invalid messages, too. Regardless of if you are putting them in or out  |
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 29, 2011 4:55 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Esa wrote: |
Well, well, the atmosphere on this forum seems to have grown quite a bit harder during my summer vacation. |
It's grown in direct proportion to the number of newbie questions of this genre.
Esa wrote: |
There is nothing wrong in using message sets, that is the way to do it even if you are using java for transforming the messages. But I would not be so categorically against string manipulation. There are cases when you simply have to use it, for example if you cannot be sure that the input message is valid and you still have to parse it. |
If it's a choice between a bit of Java rolled up in house and the wonder that kimbert and his team has delivered, I'll take the expensive IBM supplied wonder. Also in my world I don't parse invalid messages; I trap them and handle them accordinging.
Of course you need to manipulate strings as well; this is why ESQL as well as Java has the full spectrum of tools. Where I hit critical exasperation on this thread is not that a string is being manipulated but an entire, totally parsable message is being parsed and I will push back against this kind of wheel reinvention while I still have strength & will to do so.
(About 1 week I'm guessing) _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 29, 2011 5:31 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Esa wrote: |
Well, well, the atmosphere on this forum seems to have grown quite a bit harder during my summer vacation. |
It's always September. |
|
Back to top |
|
 |
joebuckeye |
Posted: Thu Sep 29, 2011 6:29 am Post subject: |
|
|
 Partisan
Joined: 24 Aug 2007 Posts: 365 Location: Columbus, OH
|
mqjeff wrote: |
It's always September. |
Too funny. |
|
Back to top |
|
 |
rekarm01 |
Posted: Thu Sep 29, 2011 8:33 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
|
Back to top |
|
 |
|