2014-02-12 31 views
-1

我的朋友們,我有一個問題,我希望你能幫助我。 這裏有一個類似的問題,但它也沒有解決: Reading 'CSV' file - Cannot read csv file contains loong string閱讀'CSV'文件 - 不顯示loong字符串

所以...這裏是我的代碼:

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"nameorg" ofType:@"csv"]; 
    NSString* fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSWindowsCP1251StringEncoding error:nil]; 
    NSMutableArray* pointStrings = [[NSMutableArray alloc] initWithArray:[fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]]; 

    for(int idx = 0; idx < [pointStrings count]; idx++) 
    { 

     NSString *currentPointString = [pointStrings objectAtIndex:idx]; 
     if ([currentPointString length] == 0) { 
      continue; 
     } 
     NSMutableArray *arr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@";"]]; 
     if ([arr count] < 5) { 
      continue; 
     } 

     NSLog(@"1: %@; 2: %@; 3: %@; 4: %@; 5: %@;", [arr objectAtIndex:0], [arr objectAtIndex:1], [arr objectAtIndex:2], [arr objectAtIndex:3], [arr objectAtIndex:4]); 
    } 

我的csv文件:

2.6.;¬ качестве адреса организации можно использовать адрес офиса учредител€, в том числе домашний адрес руководител€ фирмы, адрес арендованного помещени€.;;The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.; 
2.7.;Ёлектронна€ подача с помощью сервиса Ђѕодача электронных документов на государственную регистрациюї http://www.nalog.ru/el_usl/gosreg_eldocs/;"1. «аполнить в интерактивном режиме за€вление и направить его в налоговую инспекцию. 
2. ѕодготовить полный пакет документов в электронном виде и направить его в налоговый орган.";E-applications submission through the service ЂElectronic submission of documents for state registrationї†http://www.nalog.ru/el_usl/gosreg_eldocs/;"1 . To fill an application online and submit it to tax service. 
2 . To prepare a full set of documents in electronic form and send it to tax registration authority." 
2.8.;¬ бумажном виде;;In paper form; 

的問題:未顯示項目2.7。爲什麼?

我的NSLog:

2014-02-11 14:03:34.139 CSVSQLITE[4127:70b] 1: 2.6.; 2: В качестве адреса организации можно использовать адрес офиса учредителя, в том числе домашний адрес руководителя фирмы, адрес арендованного помещения.; 3: ; 4: The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.; 5: ; 
2014-02-11 14:03:34.163 CSVSQLITE[4127:70b] 1: 2.8.; 2: В бумажном виде; 3: ; 4: In paper form; 5: ; 

在先進的感謝這麼多。

輸出pointStrings的:

(
"2.6.;\U0412 \U043a\U0430\U0447\U0435\U0441\U0442\U0432\U0435 \U0430\U0434\U0440\U0435\U0441\U0430 \U043e\U0440\U0433\U0430\U043d\U0438\U0437\U0430\U0446\U0438\U0438 \U043c\U043e\U0436\U043d\U043e \U0438\U0441\U043f\U043e\U043b\U044c\U0437\U043e\U0432\U0430\U0442\U044c \U0430\U0434\U0440\U0435\U0441 \U043e\U0444\U0438\U0441\U0430 \U0443\U0447\U0440\U0435\U0434\U0438\U0442\U0435\U043b\U044f, \U0432 \U0442\U043e\U043c \U0447\U0438\U0441\U043b\U0435 \U0434\U043e\U043c\U0430\U0448\U043d\U0438\U0439 \U0430\U0434\U0440\U0435\U0441 \U0440\U0443\U043a\U043e\U0432\U043e\U0434\U0438\U0442\U0435\U043b\U044f \U0444\U0438\U0440\U043c\U044b, \U0430\U0434\U0440\U0435\U0441 \U0430\U0440\U0435\U043d\U0434\U043e\U0432\U0430\U043d\U043d\U043e\U0433\U043e \U043f\U043e\U043c\U0435\U0449\U0435\U043d\U0438\U044f.;;The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.;", 
    "", 
    "2.7.;\U042d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U0430\U044f \U043f\U043e\U0434\U0430\U0447\U0430 \U0441 \U043f\U043e\U043c\U043e\U0449\U044c\U044e \U0441\U0435\U0440\U0432\U0438\U0441\U0430 \U00ab\U041f\U043e\U0434\U0430\U0447\U0430 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U044b\U0445 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U043d\U0430 \U0433\U043e\U0441\U0443\U0434\U0430\U0440\U0441\U0442\U0432\U0435\U043d\U043d\U0443\U044e \U0440\U0435\U0433\U0438\U0441\U0442\U0440\U0430\U0446\U0438\U044e\U00bb http://www.nalog.ru/el_usl/gosreg_eldocs/;\"1. \U0417\U0430\U043f\U043e\U043b\U043d\U0438\U0442\U044c \U0432 \U0438\U043d\U0442\U0435\U0440\U0430\U043a\U0442\U0438\U0432\U043d\U043e\U043c \U0440\U0435\U0436\U0438\U043c\U0435 \U0437\U0430\U044f\U0432\U043b\U0435\U043d\U0438\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U0443\U044e \U0438\U043d\U0441\U043f\U0435\U043a\U0446\U0438\U044e.", 
    "2. \U041f\U043e\U0434\U0433\U043e\U0442\U043e\U0432\U0438\U0442\U044c \U043f\U043e\U043b\U043d\U044b\U0439 \U043f\U0430\U043a\U0435\U0442 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U0432 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U043e\U043c \U0432\U0438\U0434\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U044b\U0439 \U043e\U0440\U0433\U0430\U043d.\";E-applications submission through the service \U00abElectronic submission of documents for state registration\U00bb\U00a0http://www.nalog.ru/el_usl/gosreg_eldocs/;\"1 . To fill an application online and submit it to tax service.", 
    "", 
    "2 . To prepare a full set of documents in electronic form and send it to tax registration authority.\"", 
    "", 
    "2.8.;\U0412 \U0431\U0443\U043c\U0430\U0436\U043d\U043e\U043c \U0432\U0438\U0434\U0435;;In paper form;", 
    "", 
    ) 

ARR的輸出:

2014-02-11 14:07:58.545 CSVSQLITE[4249:70b] arr: (
    "2.6.", 
    "\U0412 \U043a\U0430\U0447\U0435\U0441\U0442\U0432\U0435 \U0430\U0434\U0440\U0435\U0441\U0430 \U043e\U0440\U0433\U0430\U043d\U0438\U0437\U0430\U0446\U0438\U0438 \U043c\U043e\U0436\U043d\U043e \U0438\U0441\U043f\U043e\U043b\U044c\U0437\U043e\U0432\U0430\U0442\U044c \U0430\U0434\U0440\U0435\U0441 \U043e\U0444\U0438\U0441\U0430 \U0443\U0447\U0440\U0435\U0434\U0438\U0442\U0435\U043b\U044f, \U0432 \U0442\U043e\U043c \U0447\U0438\U0441\U043b\U0435 \U0434\U043e\U043c\U0430\U0448\U043d\U0438\U0439 \U0430\U0434\U0440\U0435\U0441 \U0440\U0443\U043a\U043e\U0432\U043e\U0434\U0438\U0442\U0435\U043b\U044f \U0444\U0438\U0440\U043c\U044b, \U0430\U0434\U0440\U0435\U0441 \U0430\U0440\U0435\U043d\U0434\U043e\U0432\U0430\U043d\U043d\U043e\U0433\U043e \U043f\U043e\U043c\U0435\U0449\U0435\U043d\U0438\U044f.", 
    "", 
    "The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.", 
    "" 
) 
2014-02-11 14:07:58.548 CSVSQLITE[4249:70b] arr: (
    "2.7.", 
    "\U042d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U0430\U044f \U043f\U043e\U0434\U0430\U0447\U0430 \U0441 \U043f\U043e\U043c\U043e\U0449\U044c\U044e \U0441\U0435\U0440\U0432\U0438\U0441\U0430 \U00ab\U041f\U043e\U0434\U0430\U0447\U0430 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U044b\U0445 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U043d\U0430 \U0433\U043e\U0441\U0443\U0434\U0430\U0440\U0441\U0442\U0432\U0435\U043d\U043d\U0443\U044e \U0440\U0435\U0433\U0438\U0441\U0442\U0440\U0430\U0446\U0438\U044e\U00bb http://www.nalog.ru/el_usl/gosreg_eldocs/", 
    "\"1. \U0417\U0430\U043f\U043e\U043b\U043d\U0438\U0442\U044c \U0432 \U0438\U043d\U0442\U0435\U0440\U0430\U043a\U0442\U0438\U0432\U043d\U043e\U043c \U0440\U0435\U0436\U0438\U043c\U0435 \U0437\U0430\U044f\U0432\U043b\U0435\U043d\U0438\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U0443\U044e \U0438\U043d\U0441\U043f\U0435\U043a\U0446\U0438\U044e." 
) 
2014-02-11 14:07:58.549 CSVSQLITE[4249:70b] arr: (
    "2. \U041f\U043e\U0434\U0433\U043e\U0442\U043e\U0432\U0438\U0442\U044c \U043f\U043e\U043b\U043d\U044b\U0439 \U043f\U0430\U043a\U0435\U0442 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U0432 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U043e\U043c \U0432\U0438\U0434\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U044b\U0439 \U043e\U0440\U0433\U0430\U043d.\"", 
    "E-applications submission through the service \U00abElectronic submission of documents for state registration\U00bb\U00a0http://www.nalog.ru/el_usl/gosreg_eldocs/", 
    "\"1 . To fill an application online and submit it to tax service." 
) 
2014-02-11 14:07:58.550 CSVSQLITE[4249:70b] arr: (
    "2 . To prepare a full set of documents in electronic form and send it to tax registration authority.\"" 
) 
2014-02-11 14:07:58.551 CSVSQLITE[4249:70b] arr: (
    "2.8.", 
    "\U0412 \U0431\U0443\U043c\U0430\U0436\U043d\U043e\U043c \U0432\U0438\U0434\U0435", 
    "", 
    "In paper form", 
    "" 
) 

回答

0
2.7

沒有由於以下如果條件顯示。

if ([arr count] < 5) 
{ 
    continue; 
} 

2.7字符串只包含兩個;

NSMutableArray *arr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@";"]]; 

這將只包含3個對象,所以如果條件得到滿足。

+0

好的,我能做些什麼工作? – user3296314

+0

@ user3296314:您需要刪除該continue語句並使用循環打印該數組的內容。 –

+0

工作!感謝Midhun MP))))) – user3296314