xcode - Chinese characters garbled -
i wrote servlet download database records include chinese characters. download file in csv format. servlet response content type set "text/csv; charset=utf-8".
when open csv in excel, chinese chars unreadable. but, if open same file using xcode editor, show fine.
i not able find setting char encoding in either application.
what can difference between excel , xcode editor?
it may limitation of excel's handling of csv files. can try tab separated format txt
extension:
nsdictionary *dictionary = @{@"(nǐ hǎo) - inf" : @"你好", @"(hǎojǐu bújiàn)" : @"好久不見 [好久不见]"}; nsstring *documentspath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes)[0]; nsstring *path = [documentspath stringbyappendingpathcomponent:@"test.txt"]; nsmutablestring *string = [nsmutablestring string]; (nsstring *key in dictionary) { [string appendstring:key]; [string appendstring:@"\t"]; [string appendstring:dictionary[key]]; [string appendstring:@"\n"]; } nserror *error; bool success = [string writetofile:path atomically:yes encoding:nsutf16stringencoding error:&error]; nsassert(success, @"error = %@", error);
i able open file in excel. had use nsutf16stringencoding
, not nsutf8stringencoding
.
Comments
Post a Comment