This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to compare a string using String tokenizer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to compare a string using String tokenizer" Watch "how to compare a string using String tokenizer" New topic
Author

how to compare a string using String tokenizer

scandalous kk
Greenhorn

Joined: Feb 22, 2009
Posts: 1
hello
my string is
str=" processor : intel pentium "
i am using string tokenizer to print each word from str except the colon
so that my output should look like
processor
intel
pentium
=====
instead of
processor
:
intel
pentium

can anyone help me
thnx in advance

Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2796
    
    9

"scandalous kk " welcome to Javaranch
please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
Phuc Bui
Greenhorn

Joined: Feb 19, 2009
Posts: 26
Hi,
First you can use StringTokenizer with colon as delimitation.
You get:
processor
intel pentium

Then use StringTokenizer again with whitespace as delimitation.
You will get
processor
intel
pentium

It's complex, isn't it ?
Or you can do it with your own code, without using StringTokenizer

Cheers,

Phuc Bui
 
Have you checked out Aspose?
 
subject: how to compare a string using String tokenizer
 
It's not a secret anymore!