Article View: borland.public.jbuilder.java.language
Article #8684Re: Can you use a String as a delimeter in StringTokenizer
From: Alex Colic
Date: Tue, 06 Mar 2001 20:00
Date: Tue, 06 Mar 2001 20:00
50 lines
2807 bytes
2807 bytes
Thanks, I will try your suggestion.
Alex
"Paul Furbacher [TeamB]" <pf@bilbo.bio.purdue.edu> wrote in message
news:3AA53C54.39ED719B@bilbo.bio.purdue.edu...
>
> Alex Colic wrote:
> >
> > Hi, here is my complete code. In my previous example I used "!" as the
> > delimiter . I meant "Category!". I could not get it to parse correctly
with
> > the latter delimiter so I tried the former.
> >
> > String text="Category!Commodity Code";
> > String strCategoryPreAppend="Category!";
> > StringTokenizer token=new StringTokenizer(text,
> > strCategoryPreAppend);
> >
> > System.out.println("Count: " + token.countTokens());
> > while(token.hasMoreElements())
> > {
> > System.out.println("Token: " + token.nextElement());
> > }
> >
> > Count: 4
> > Token: mm
> > Token: di
> > Token:
> > Token: d
> >
> > What I expect is two tokens: "Category" and "CommodityCode."
>
> If you can drill down into the StringTokenizer class,
> look at the scanToken() method. You'll notice that it
> decomposes the "str" one character at a time from a
> starting position. It then asks, "is this character in
> the "delimiters" by checking for an indexOf() >= 0.
> So, the approach taken by StringTokenizer to get tokens
> is just about backwards from the way you (and many others)
> think it should be working (i.e., looking for the string
> you give as the delimiters as a substring of the source
> string).
>
> If you use the "!" as a delimiter, you can look for "Category"
> token in a loop. When you find it, grab the next token and
> then break out of the loop.
>
>
> Paul Furbacher (TeamB)
> - Please send responses to newsgroups only. Thank you.
Technical Details
Message-ID:
<983fi2$58g11@bornews.inprise.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mailReferences:
<9810gn$fl1@bornews.inprise.com> <MPG.150e8591d5d31fe998a014@forums.borland.com> <982rcl$n9q4@bornews.inprise.com> <3AA53C54.39ED719B@bilbo.bio.purdue.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,22501d0a26c51927 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-06 12:08:06 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mail From: "Alex Colic" <alex.colic@pop-ware.com> Newsgroups: borland.public.jbuilder.java.language Subject: Re: Can you use a String as a delimeter in StringTokenizer Date: Tue, 6 Mar 2001 15:00:06 -0500 Organization: Another Netscape Collabra Server User Lines: 52 Message-ID: <983fi2$58g11@bornews.inprise.com> References: <9810gn$fl1@bornews.inprise.com> <MPG.150e8591d5d31fe998a014@forums.borland.com> <982rcl$n9q4@bornews.inprise.com> <3AA53C54.39ED719B@bilbo.bio.purdue.edu> NNTP-Posting-Host: d150-29-218.home.cgocable.net X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200