0

I try split values of sql for modify values (DATE, boolean, ...). For example, I have the values:

('im a value','im a second value with, test',478,20/05/2010 16:56:32)

How i can split the value for had only 4 values:

  • 'im a value'
  • 'im a second value with, test'
  • 478
  • 20/05/2010 16:56:32

and not 5 values:

  • 'im a value'
  • 'im a second value with
  • test'
  • 478
  • 20/05/2010 16:56:32

Thanks

edit:

new exemple:

  INSERT INTO ACCES (id,type,com, date,make) VALUES (478,'action','test commentaire, new test',20/05/2010 16:56:3,False);

result

 INSERT INTO ACCES (id,type,com, date,make) VALUES (478,'action','test commentaire, new test',1274367363,0);
user1238096
  • 15
  • 1
  • 5
  • Not sure what you mean, there are only two values, the comma is part of the second value. The apostrophe in SQL is a field delimiter. – twoleggedhorse Jan 07 '13 at 13:25
  • It's like he's getting it all as a String and trying to `split` on the `,`, effectively chopping off at the comma in-between the `'` too. – karllindmark Jan 07 '13 at 13:33
  • We need more details about your problem. How / where are stored those values (uniaue string, database etc)? – Miloš Jan 07 '13 at 13:35

2 Answers2

1

You can do this iteratively, or you can do it this way:

Java: splitting a comma-separated string but ignoring commas in quotes

In short, you split with a regular expression:

line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
Community
  • 1
  • 1
wentam
  • 26
  • 1
0

I know only one way to do that.

  1. Split input string by "," to array
  2. If I string starts with "'" and (I+1) string end with "'" then combine it to I element
  3. Remove I+1 element

If you need realisation, I can write it later

Spyric
  • 161
  • 9