How to always apply quotes (escape) in Super CSV

喜欢而已 提交于 2019-12-12 02:38:23

问题


i would like to put my file csv like this forma:

"User 2";"Web Page" ;"AbdelMonem NAAMANE";;;;

i make my own Csv Preference like that:

private static final CsvPreference myPreference = new CsvPreference.Builder('"',';''\n').build();

i would like to have a header like that "User 2";"Web Page"


回答1:


It's hard to see what you're doing without a complete code example, but from your post on the Super CSV bug tracker, I suspect that you're asking how to always quote CSV fields.

There's extensive documentation on the Super CSV website on how to configure custom preferences - the feature you're after is the quote mode.

Here's an example of using the AlwaysQuote quote mode, which quotes every field even if it doesn't contain special characters.

CsvPreference prefs = new CsvPreference.Builder('"',';',"\n")
    .useQuoteMode(new AlwaysQuoteMode()).build();

ICsvListWriter writer = new CsvListWriter(new OutputStreamWriter(System.out), 
    prefs);
writer.writeHeader("User2", "Web Page");
writer.flush();

Which prints:

"User2";"Web Page"


来源:https://stackoverflow.com/questions/21427523/how-to-always-apply-quotes-escape-in-super-csv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!