• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing a String

 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a not so difficult string parsing algorithm, Scanner proves useful.

Try it out and let us know whether you got what you desired
 
arulk pillai
Author
Ranch Hand
Posts: 3387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a simple parser to convert it to the format you want it in.

Regex can be useful
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15278
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 48938
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think DB is correct; everybody posting ought to know about other discussions. Read this FAQ.
 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it solved,
For anyone having future use, this is how I solved.


which gave me the output

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic