Reputation: 47
My CSV file look like this
"Gates Nissan of Richmond" , "L2T Media, Llc" , "7000000", "--"
I want to remove comma(,) from this "L2T Media, Llc"
in CSV
so that, my output will be "L2T Media Llc"
How can I do this in Java coding?
Upvotes: 1
Views: 2820
Reputation: 253
You could try something like this:
String str = "\"Gates Nissan of Richmond\" , \"L2T Media, Llc\" , \"7000000\", \"--\"";
List<String> items = new ArrayList<String>();
for(String item : Arrays.asList(str.substring(1, str.length()-1).split("\"+\\s*,\\s*\"+")))
items.add("\"" + item.replace(",", "") + "\"");
System.out.println(items);
Output:
["Gates Nissan of Richmond", "L2T Media Llc", "7000000", "--"]
Upvotes: 1
Reputation: 16209
Based on this answer:
public static void main(String[] args) {
String s = "\"Gates Nissan of Richmond\" , \"L2T Media, Llc\" , \"7000000\", \"--\"";
String[] splitted = s.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
for(String item : splitted) {
item.replaceAll(",", "");
}
}
Upvotes: 0