Reputation:
I want to split this string and put the values in to my tables of database.I am thinking of using string tokenizer class or some other way. please let me the best method and how to implement it practically with code.
Upvotes: 2
Views: 296
Reputation: 80340
It looks like CSV, so you could use any of the recommended Java CSV libraries: Can you recommend a Java library for reading (and possibly writing) CSV files?
Upvotes: 5
Reputation: 5666
If you can assure that never will there be a "," inside a pair of ", then the .split-Solution is your way to go.
Upvotes: 0
Reputation: 38043
Assuming there are no commas in your strings
String[] ss = s.split(",");
will do it
If you have strings such as
"Foo, Bar"
Then you will need a Pattern and regex and chop off each matched group. See http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html
However your target string is unclear. Does it have a newline in or does it have two target strings? If the former you will need:
String[] ss = s.split("[,\\n]");
But I am worried that your problem is not sufficiently clearly defined
Upvotes: 1
Reputation: 6411
You should use split() methnod from String class instead of StringTokenizer class. StringTokenizer class is less efficient than String.split() method.
Upvotes: 0