在mac環(huán)境中將上面的excel轉(zhuǎn)成plist:
1.將表格拷貝到文本編輯器中,去除掉第一行的Countries and Regions,?國家或地區(qū),?國際域名縮寫,電話代碼,時差等文字(注意,最后一行也不能留空白,否則代碼轉(zhuǎn)換會讀取不到,發(fā)生崩潰)
2.在文本編輯器中按下快捷鍵:shift?+command?+T.
再保存的時候就會出現(xiàn)(轉(zhuǎn)換成utf-8編碼):
3.將保存的文件加入工程中,并使用如下代碼進(jìn)行轉(zhuǎn)換
NSString*alarmPath = [[NSBundlemainBundle]pathForResource:@"countrycode"ofType:@"txt"];
//NSLog(@"%@",alarmPath);
//嘗試更換文件編碼挤悉,失敗
//NSStringEncoding gbk = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString*alarmContent = [[NSStringalloc]initWithContentsOfFile:alarmPathencoding:NSUTF8StringEncodingerror:nil];
//NSLog(@"%@",alarmContent);
NSArray*alarmArray = [alarmContentcomponentsSeparatedByCharactersInSet:[NSCharacterSetnewlineCharacterSet]];
//NSLog(@"%@",alarmArray);
NSString*docuPath = [NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
NSString*plistPath = [docuPathstringByAppendingPathComponent:@"countryCode.plist"];
NSLog(@"%@",plistPath);
NSMutableArray*resultsArr = [NSMutableArrayarray];
for(NSIntegerj =0; j < alarmArray.count; j++){
NSString*alarmStr = [alarmArrayobjectAtIndex:j];
//NSLog(@"%@",alarmStr);
NSArray*alarmArr = [alarmStrcomponentsSeparatedByString:@"\t"];
[resultsArraddObject:@{@"country":[alarmArrobjectAtIndex:0],@"Chinese":[alarmArrobjectAtIndex:1],@"abbr":[alarmArrobjectAtIndex:2],@"code":[alarmArrobjectAtIndex:3],@"jetLag":[alarmArrobjectAtIndex:4]}];
}
[resultsArrwriteToFile:plistPathatomically:YES];
結(jié)束;