A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
How to read follwing String
Joined: Mar 23, 2010
Mar 23, 2010 05:42:37
I have following
. I want to separate this String in key value pair like.
srno as key and 20090001 as value. Don't want to use StringTokenzier.
String str = " srno= 20090001 , name = 'Na,mit', add = ' road' "
Thank you !!!
Joined: Jan 28, 2008
Mar 23, 2010 06:20:57
Welcome to JavaRanch Prajakta Kale
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 ?
Joined: Oct 13, 2005
Mar 23, 2010 09:01:42
Welcome to the Ranch
You are right not to use
; use the
method of String, and try a small limit, maybe 2.
Joined: Jun 04, 2007
Mar 23, 2010 11:43:58
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.
SCJP - 86% - June 11, 2009
I agree. Here's the link:
subject: How to read follwing String
Validation rule for array of objects.
how to open a child window in struts2
Issue with the thread when calling third party Web service
getting the first four characters from a line
Display value and Actual value in JComboBox
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014