ios解析csv檔案

2021-06-20 10:50:57 字數 858 閱讀 5973

nsstring

*path = [[

nsbundle

mainbundle] pathforresource:

@"citys"

oftype:@"csv"];

nsstringencoding

gbkencoding =cfstringconvertencodingtonsstringencoding(kcfstringencodinggb_18030_2000);

nsdata *data = [nsdata

datawithcontentsoffile:path];

nsstring *string2 = [[nsstring

alloc]initwithdata:data encoding:gbkencoding];

nsstring* filecontents =

[nsstring

stringwithcontentsoffile:path

encoding:gbkencoding error:nil];

nsarray* alllinedstrings =[string2 componentsseparatedbystring:@"\n"];

self.poitypes = [[nsmutabledictionary

alloc] initwithcapacity:[alllinedstrings count]];

for (int i = 0; icount; i++)

alllinedstrings陣列裡每個元素是csv列表裡的一橫排字元

poitypes字典裡是把每一橫排字元通過逗號分隔成乙個小陣列,然後把這個小陣列的第乙個元素作為key,把小陣列作為value

解析csv檔案

以下內容僅為記錄 第一步 解析csv檔案 test public void testcsv throws exception catch filenotfoundexception e string line string everyline try system.out.println csv 中...

CSV檔案解析

實現功能 針對讀取的csv文件字串進行map格式輸出 主要 如下 public class csvpaser extends parser public static void main string args system.out.println map 說明 該部分主要針對多條記錄做相應的解析 ...

Golang解析CSV檔案

日常工作實用csv型別檔案很普遍,而且很容易從其他資料來源中獲得。如google sheets,microsoft excel,或關係型資料庫。如何在應用中載入並解析csv呢,本文帶你實用golang解析csv檔案。通常其他語言處理csv檔案比較麻煩,通常需要通過第三方庫,解析工作量較大。golan...