File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Parsing a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing a String" Watch "Parsing a String" New topic
Author

Parsing a String

anees ahamed
Ranch Hand

Joined: Feb 19, 2008
Posts: 31
Hi all,
Let me first say that I have posted this in sun forums and it didnt work out for me.
I am reframing my question here for your valuable suggestions and comments.

This is the general format in which I get data from database(This is an example where the group names and user names are variables and the other syntax will be exactly the same). Literally I do not know what kind of string is this and what to do with this.


I need an output of the format





For users with no groups, it should be



I would like to have these outputs in some array or as any collection
in Java. How can I accomplish this?

Anees
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

For a not so difficult string parsing algorithm, Scanner proves useful.

Try it out and let us know whether you got what you desired


apigee, a better way to API!
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
Write a simple parser to convert it to the format you want it in.

Regex can be useful


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

Originally posted by anees ahamed:

Let me first say that I have posted this in sun forums and it didnt work out for me.


Thank you for declaring this right at the onset. We really appreciate it.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Originally posted by anees ahamed:
Literally I do not know what kind of string is this and what to do with this.

It looks like JSON. There are a number of Java libraries available to parse JSON, they are listed on the website.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Originally posted by Maneesh Godbole:


Thank you for declaring this right at the onset. We really appreciate it.

What's not so nice is continuing the topic on the other forum even after posting here, not mentioning the cross post on the other forum, and not providing a link.
http://forums.sun.com/thread.jspa?threadID=5342229


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
I think DB is correct; everybody posting ought to know about other discussions. Read this FAQ.
anees ahamed
Ranch Hand

Joined: Feb 19, 2008
Posts: 31
I got it solved,
For anyone having future use, this is how I solved.


which gave me the output

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing a String
 
Similar Threads
liferay database migration
Hibernate - empty collections don't work with Criterias
Need Ideas for This Puzzle
Java on Unix: /home or /usr ?
How to achieve composition