ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Split String in JAVA COMPUTE NODE

Post new topic  Reply to topic Goto page 1, 2  Next
 Split String in JAVA COMPUTE NODE « View previous topic :: View next topic » 
Author Message
nukalas2010
PostPosted: Tue Sep 27, 2011 10:40 pm    Post subject: Split String in JAVA COMPUTE NODE Reply with quote

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
View user's profile Send private message
kevinobyrne
PostPosted: Wed Sep 28, 2011 1:19 am    Post subject: Reply with quote

Voyager

Joined: 17 Jul 2007
Posts: 83
Location: Ireland

What's wrong with using a message set and esql/mapping node?
Back to top
View user's profile Send private message
saurabh867
PostPosted: Wed Sep 28, 2011 1:21 am    Post subject: Reply with quote

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
View user's profile Send private message
anandsitha
PostPosted: Wed Sep 28, 2011 3:08 am    Post subject: Reply with quote

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
View user's profile Send private message
nukalas2010
PostPosted: Wed Sep 28, 2011 3:39 am    Post subject: Reply with quote

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
View user's profile Send private message
kevinobyrne
PostPosted: Wed Sep 28, 2011 4:03 am    Post subject: Reply with quote

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
View user's profile Send private message
zpat
PostPosted: Wed Sep 28, 2011 4:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Wed Sep 28, 2011 4:55 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Wed Sep 28, 2011 4:59 am    Post subject: Reply with quote

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
View user's profile Send private message
Gaya3
PostPosted: Wed Sep 28, 2011 5:45 am    Post subject: Reply with quote

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
View user's profile Send private message
Esa
PostPosted: Thu Sep 29, 2011 1:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Thu Sep 29, 2011 4:55 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Thu Sep 29, 2011 5:31 am    Post subject: Reply with quote

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
View user's profile Send private message
joebuckeye
PostPosted: Thu Sep 29, 2011 6:29 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

mqjeff wrote:
It's always September.


Too funny.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Thu Sep 29, 2011 8:33 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

mqjeff wrote:
It's always September.

See http://en.wikipedia.org/wiki/Eternal_September. See also http://www.df7cb.de/projects/sdate/.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Split String in JAVA COMPUTE NODE
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.