my dog learned polymorphism*
The moose likes Java in General and the fly likes Reading values from 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 "Reading values from a String" Watch "Reading values from a String" New topic
Author

Reading values from a String

siva sankar
Ranch Hand

Joined: Jul 13, 2006
Posts: 68
Hi,
I am hitting a webservice which is returning a String as shown below.

String output="identitydetails.attribute.name=uid
identitydetails.attribute.value=John
identitydetails.attribute.name=mail
identitydetails.attribute.value=john@abc.com
identitydetails.attribute.name=sn
identitydetails.attribute.value=D";


In the above output,each line contains a attribute name and the next corresponding line have the value for this attribute.
For example,the line1 and line2 in above output is identitydetails.attribute.name=uid and identitydetails.attribute.value=John.
Now I want to add uid(from line1) as a key and John(from line2) as value to a HashMap. The same has to be done for other lines in the output and add key/value pairs to HashMap.


Can anyone suggest me the best approach to achieve the above requirement.

Thanks in Advance,
SivaReddy
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
That is the name=value format used by "properties" so you could create a java.util.Properties object to hold and read values.

Create a StringReader from the String, create an empty Properties and then load it from the Reader.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading values from a String
 
Similar Threads
How to dinamically populate a String array?
Little Silly but not able to get
BufferedReader issue?
Problem with Javascript string comparison
String methods....