Closed ShijunK closed 9 years ago
Hey! ShijunK can we replace the delimiter from "," to any other one(Symbol) then it should not take "," as a delimiter
hi dOngithub, I am talking about escaping a delimiter within quoted content, to csv format, using double quoting is quite a common practice to escape comma though there is no such an industry standard. Yes, we can work around this issue by using a different delimiter. However, in real world, many times you will find little or no choice about what you are receiving from upstream/outside partner. Instead do adhoc hack, you really want a framework like gs-collections to do the right thing when it claims it is capable to do so ( csvTokensToList ).
@dOngithub http://tools.ietf.org/html/rfc4180
Implementing full csv parsing is beyond the scope of GS Collections. We have deprecated the StringIterate.csv* methods since they don’t handle cases such as quoted strings, embedded commas and quotes, newlines, etc. Instead, we’d suggest using a separate library for proper csv parsing. If that library returns an array of tokens, you can use ArrayAdapter to get the MutableList API.
csv is not as simple as StringIterate.tokensToList(string, ",");, a csv parser should be able to support quoted field which means comma within double quoted field should not be treated as a delimit.
test case:
String str = "a, b,\ "c,d\""; Verify.assertListsEqual(FastList.newListWith("a", "b", "c,d"), StringIterate.csvTokensToList(str));