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 » ESQL Query

Post new topic  Reply to topic Goto page 1, 2  Next
 ESQL Query « View previous topic :: View next topic » 
Author Message
anoobrocks
PostPosted: Tue Sep 28, 2010 1:45 am    Post subject: ESQL Query Reply with quote

Newbie

Joined: 28 Sep 2010
Posts: 8

Hi,
Can anyone suggest, the keyword/type/statement/function used to find the number of characters in a string without using any loops.

eg) Name='WebsphereMessageBroker', to find the number of 'e' in it, this should return an output - 6.

Thank you.
Back to top
View user's profile Send private message
WMBDEV1
PostPosted: Tue Sep 28, 2010 1:56 am    Post subject: Reply with quote

Sentinel

Joined: 05 Mar 2009
Posts: 888
Location: UK

I'm confused as your opening statement suggested you want to find a the length of a string but your exmaple shows something different.

What have you tried searching for to find the LENGTH or POSITION of a string within a string? Have you looked at the info center for some string manipulation statements / functions that may help?
Back to top
View user's profile Send private message
exerk
PostPosted: Tue Sep 28, 2010 2:25 am    Post subject: Reply with quote

Jedi Council

Joined: 02 Nov 2006
Posts: 6339

Moving to the Broker forum...

...anoobrocks, please be more careful in which forum you post, thank you
_________________
It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys.
Back to top
View user's profile Send private message
anoobrocks
PostPosted: Tue Sep 28, 2010 3:24 am    Post subject: Reply with quote

Newbie

Joined: 28 Sep 2010
Posts: 8

I mean to find the number of a specific characters like 'e' or any special char in a string.. position cant help to resolve this..
Back to top
View user's profile Send private message
WMBDEV1
PostPosted: Tue Sep 28, 2010 3:47 am    Post subject: Reply with quote

Sentinel

Joined: 05 Mar 2009
Posts: 888
Location: UK

anoobrocks wrote:
position cant help to resolve this..


Well it can.... if you get over your fear of loops. Why this restriction?

There are other methods available that I can think of but i'd like to understand your restriction before suggesting these.

Apologies for my earlier post also, it seems your posting was clearer when I re-read it the second time and understood what you were trying to do!


Last edited by WMBDEV1 on Tue Sep 28, 2010 3:48 am; edited 1 time in total
Back to top
View user's profile Send private message
firoj.badsa
PostPosted: Tue Sep 28, 2010 3:48 am    Post subject: Reply with quote

Centurion

Joined: 16 Feb 2007
Posts: 104

may be this can help ... .. (not tested)

i=1;
count =0;
get the LENGTH of source string.

while(i<= LENGTH) DO

IF(POSITION('E' IN 'STRING' FROM i)>0) THEN
set k = 1;
else
set k = 0;
END IF;
count = count + k;
i = i +1;
end while;
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Sep 28, 2010 4:17 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Did someone ask you this question in an interview?
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Tue Sep 28, 2010 4:22 am    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi All,

This is the first time I've heard of such a requirement...I'd second mqjeff's thought of it being an interview question...

Anyway, personally I'd implement this as a Java function with string tokenizer or something.

Regards.
Back to top
View user's profile Send private message Send e-mail
anoobrocks
PostPosted: Tue Sep 28, 2010 4:32 am    Post subject: Reply with quote

Newbie

Joined: 28 Sep 2010
Posts: 8

Thanks all for the reply..

I gave the same ans saying it is possible by position & looping.. the same way as u suggested.. but i was asked to try without usng a loop eventhough i said its not possible.. so wanna confirm by raising it here..
Back to top
View user's profile Send private message
WMBDEV1
PostPosted: Tue Sep 28, 2010 4:37 am    Post subject: Reply with quote

Sentinel

Joined: 05 Mar 2009
Posts: 888
Location: UK

anoobrocks wrote:
i said its not possible.. so wanna confirm by raising it here..


I disagree then. It is possible to do it without a loop. I can think of two ways off the top of my head but it seems like a pointless exercise other than a theoretical one.
Back to top
View user's profile Send private message
vmcgloin
PostPosted: Tue Sep 28, 2010 4:42 am    Post subject: Reply with quote

Knight

Joined: 04 Apr 2002
Posts: 560
Location: Scotland

Of course there are way of doing it without a loop. The first that comes to mind is to use TRANSLATE and compare the lengths of the source string and the returned string.

But I hope the rest of the interview questions were more relevant to real-life.
Back to top
View user's profile Send private message
WMBDEV1
PostPosted: Tue Sep 28, 2010 4:46 am    Post subject: Reply with quote

Sentinel

Joined: 05 Mar 2009
Posts: 888
Location: UK

vmcgloin wrote:
Of course there are way of doing it without a loop. The first that comes to mind is to use TRANSLATE and compare the lengths of the source string and the returned string.


Ditto. The second approach being a convaluted recursion approach.

Equally pointless
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Sep 28, 2010 4:50 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

vmcgloin wrote:
But I hope the rest of the interview questions were more relevant to real-life.



_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Sep 28, 2010 4:51 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

anoobrocks wrote:
but i was asked to try without usng a loop eventhough i said its not possible..


So it was an interview question?

We don't do that. Don't ask those here.

it is possible to do this without using a loop.
Code:
Set Environment.Variables.Input = 'HelloWorldWhatAGreatWorldItIs';
Set Environment.Variables.Key = 'World' ;
Set Environment.Variables.Replaced = REPLACE(Environment.Variables.Input,Environment.Variables.Key,'');
Set Environment.Variables.Result = (LENGTH(Environment.Variables.Input)-Length(Environment.Variables.Replaced))/Length(Environment.Variables.Key);


EDIT: In the time it took me to actually test this, the gist of this was already posted.

Although incorrectly. TRANSLATE is the wrong function to use.

And complicated recursion is still looping.
Back to top
View user's profile Send private message
vmcgloin
PostPosted: Tue Sep 28, 2010 5:19 am    Post subject: Reply with quote

Knight

Joined: 04 Apr 2002
Posts: 560
Location: Scotland

Fair enough - it was just a thought... but please can you put me out of my misery now and tell me why REPLACE and not TRANSLATE? I would suggest that the requirements were not clear enough for either of us to generalise.

The original question was to count the number of occurrences of a given character 'e'. You counted the number of occurrences of a given substring 'World', but equally you could have generalised to count the number of vowels in which case TRANSLATE would be the better option.

Anyway.. back to work...
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 » ESQL Query
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.