Dealing with commas in a CSV file

后端 未结 27 2758
傲寒
傲寒 2020-11-21 06:53

I am looking for suggestions on how to handle a csv file that is being created, then uploaded by our customers, and that may have a comma in a value, like a company name.

27条回答
  •  执笔经年
    2020-11-21 07:22

    I generally URL-encode the fields which can have any commas or any special chars. And then decode it when it is being used/displayed in any visual medium.

    (commas becomes %2C)

    Every language should have methods to URL-encode and decode strings.

    e.g., in java

    URLEncoder.encode(myString,"UTF-8"); //to encode
    URLDecoder.decode(myEncodedstring, "UTF-8"); //to decode
    

    I know this is a very general solution and it might not be ideal for situation where user wants to view content of csv file, manually.

提交回复
热议问题