我正嘗試爲一個字符串分隔像下面只返回數字。 從第一個文件的輸出是這樣的:字符串後separatedBy
輸出文件1:
contents: 2017-07-31 16:29:53,0.10109999,9.74414271,0.98513273,0.15%,42302999779,-0.98513273,9.72952650
2017-07-31 16:29:53,0.10109999,0.25585729,0.02586716,0.25%,42302999779,-0.02586716,0.25521765
rows: ["2017-07-31 16:29:53,0.10109999,9.74414271,0.98513273,0.15%,42302999779,-0.98513273,9.72952650", "2017-07-31 16:29:53,0.10109999,0.25585729,0.02586716,0.25%,42302999779,-0.02586716,0.25521765", "", ""]
輸出文件2:
contents: 40.75013313,0.00064825,5/18/2017 7:17:01 PM
19.04004820,0.00059900,5/19/2017 9:17:03 PM
rows: ["4\00\0.\07\05\00\01\03\03\01\03\0,\00\0.\00\00\00\06\04\08\02\05\0,\05\0/\01\08\0/\02\00\01\07\0 \07\0:\01\07\0:\00\01\0 \0P\0M\0", "\0", "1\09\0.\00\04\00\00\04\08\02\00\0,\00\0.\00\00\00\05\09\09\00\00\0,\0\05\0/\01\09\0/\02\00\01\07\0 \09\0:\01\07\0:\00\03\0 \0P\0M\0", "\0", "\0", "\0"]
所以這兩個文件是可讀的字符串,因爲print(content)
是加工。 但是,只要字符串分開,第二個文件就不可讀了。 我嘗試了不同的編碼,但沒有任何工作。有沒有人有一個想法,如何強制字符串到第二個文件,保持一個可讀的字符串?
它必須與編碼有關。你能上傳你的原始csv文件嗎? – nathan
這是關係到你以前的,現在被刪除的問題https://stackoverflow.com/questions/45662712/problems-with-csv-file-type? - 您是否按照我的建議嘗試了'CSVReader(stream:stream,codecType:UTF16.self,endian:.big/.little)'? –
請參閱https://stackoverflow.com/questions/18851558/ios-whats-the-best-way-to-detect-a-files-encoding以自動檢測編碼。 –