aspose file tools
The moose likes Java in General and the fly likes Use StringTokenizer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Use StringTokenizer" Watch "Use StringTokenizer" New topic
Author

Use StringTokenizer

Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 273
I have a string

id,name,status,resourceStatus,;requirement,description,owner,permission,

I want to convert it into

id;name;status;resourceStatus;, requirement;description;owner;permission;
Can anyone tell me this, how should I do it with StringTokenizer?

Thanks in Advance
Grishma
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

Here is what JavaDoc tells about StringTokenizer class ..

The string tokenizer class allows an application to break a string into tokens.



String#replace() , method helps !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Any specific reasons to use StringTokenizer?
Since JDK 5, Scanner will be a better option.


apigee, a better way to API!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Originally posted by Sagar Rohankar:
String#replace() , method helps !!

Not in this case, or at least not directly. The ; and , need to be switched around. As with all swapping, you will need some temporary replacement or you will lose one of the two.

replace could work as follows:

Of course this will cause more problems if | is in the string.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Use StringTokenizer
 
Similar Threads
The Perennial Lazy loading dilemma from the heart of a novice
Could not execute JDBC batch update
Can anyone tell why is this query not valid?
Query Optimization
StringTokenizer