This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to read follwing String  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi,

I have following string . I want to separate this String in key value pair like.

srno as key and 20090001 as value. Don't want to use StringTokenzier.

please help....



String str = " srno= 20090001 , name = 'Na,mit', add = ' road' "

Thank you !!!
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<EDIT>
Welcome to JavaRanch Prajakta Kale
</EDIT>

if you dont want to use predefined spliting mechnism, you need to implement two methods 1. String[] getKeys 2. String[] getValues.

by the way: how do you get only keys as well as only values ?
 
Marshal
Posts: 59728
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You are right not to use StringTokenizer; use the split() method of String, and try a small limit, maybe 2.
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider a nested pair of splits....

an outer doing a split(",") to separate each of the key value pairs...
for each token
an inner doing a split("=") to separate each key and value
then do a put (key, value)

now watch out..... some of your strings(values) have single quotes. They are already inside a string so the single quotes will be taken in as part of the value string.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!