aspose file tools*
The moose likes Java in General and the fly likes Alternative to string tokenzier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Alternative to string tokenzier" Watch "Alternative to string tokenzier" New topic
Author

Alternative to string tokenzier

Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Hi Folks ,

I am currently using StringTokennizer class to split a String into different tokenas by defined delimiter


My query is that did jdk 1.5 , provides us with any other alternatives to achieve this same thing like regex and matching pattern or split() of string class..!!please advise..!!
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I think it was discussed enough here:
http://www.coderanch.com/t/326006/java/java/String-split-Vs-StringTokenizer
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Use split ...

Then iterate through the tokens[] array.

Pat.
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

William P O'Sullivan wrote:Use split ...

Then iterate through the tokens[] array.

Pat.


Hi William ,

can you show through split(), it would be a great help if you could convert mine program , in your approach , showing the use of split()..!!thanks in advance..!
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

William P O'Sullivan wrote:Use split ...

Then iterate through the tokens[] array.

Pat.


My second query is that which one we should choose tokenzier of split()..??please advise..!! thanks in advance..!!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Saral Saxena wrote:
William P O'Sullivan wrote:Use split ...

Then iterate through the tokens[] array.

Pat.


Hi William ,

can you show through split(), it would be a great help if you could convert mine program , in your approach , showing the use of split()..!!thanks in advance..!


Please try doing your own work, rather than asking for someone to do it for you.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

I already gave you the split() code, now all you have to do is change the while()
to something else ... ;)

as for which one to use, depends on the need.

StringTokenizer has the ability to return the token as one of the elements, in your case ","
would appear in the collection of tokens. split() does not include the delimiter.

Pat.


Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Hi Folks ,

I am currently using StringTokennizer class to split a String into different token as by defined delimiter


My query is that can same thing can also be achieved through scanner class also ...!! Is it the right approach to use the scanner class since I was reading The Scanner class allows you to tokenize data from within a loop, which allows you to stop whenever you want to...
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Saral Saxena wrote:
My query is that can same thing can also be achieved through scanner class also ...!!


So study the details of the Scanner class, and see if you can make it work that way.

And really, a single punctuation mark is sufficient to end a sentence. More that is just distracting clutter that makes your post unpleasant to read.
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Jeff Verdegan wrote:
Saral Saxena wrote:
My query is that can same thing can also be achieved through scanner class also ...!!


So study the details of the Scanner class, and see if you can make it work that way.

And really, a single punctuation mark is sufficient to end a sentence. More that is just distracting clutter that makes your post unpleasant to read.


Hi Jeff,

I have tried this but it not producing the result please guide me ,,how to correct this to produce the result..
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Saral Saxena wrote:

I have tried this but it not producing the result please guide me ,,how to correct this to produce the result..


ItDoesntWorkIsUseless.(⇐click) You have to TellTheDetails(⇐click) of what exactly you expected to happen and what exactly happened instead.

And by now, with all the threads you've posted and all the times you've been reminded, you should know that you need to show some effort and that you need to tell the details without someone having to remind you every single time.

Please keep this in mind for future posts. Thanks.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

I really dislike StrinkgTokenizer(), I think it should be @deprecated and removed. For most complex splits, I much prefer the Google Guava packages.

com.google.common.base.Splitter

for this specific case.

Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 202

Pat Farrell wrote:I really dislike StrinkgTokenizer(), I think it should be @deprecated and removed. For most complex splits, I much prefer the Google Guava packages.

com.google.common.base.Splitter

for this specific case.



output i need such as....

---- Split by comma ',' ------
This is String
split by StringTokenizer
created by saral
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alternative to string tokenzier