Can not convert from Japanese text string to NSUTF8StringEncoding
This is the original string:
"101","çÇìc éOòY","¿∂¿ﬁªÃﬁ€≥","100", "102","êÛìc å‹òY","±ª¿ﬁ∫ﬁ€≥","100", "103","é·ìc ëÂï„","‹∂¿¿ﬁ≤Ωπ","100", "104","ïêìc ëæòY","¿π¿ﬁ¿€≥","200", "105","çÇå¥Å@èü","¿∂ ◊œªŸ","200", "106","è¨ñÏÅ@é¿","µ…–…Ÿ","300", "107","ê¥êÖÅ@óyçÅ","º–Ωﬁ Ÿ∂","300",
This is what I want:
"101","高田 三郎","ﾀｶﾀﾞｻﾌﾞﾛｳ","100", "102","浅田 五郎","ｱｻﾀﾞｺﾞﾛｳ","100", "103","若田 大輔","ﾜｶﾀﾀﾞｲｽｹ","100", "104","武田 太郎","ﾀｹﾀﾞﾀﾛｳ","200", "105","高原 勝","ﾀｶﾊﾗﾏｻﾙ","200", "106","小野 実","ｵﾉﾐﾉﾙ","300", "107","清水 遥香","ｼﾐｽﾞﾊﾙｶ","300",
I code like this:
NSString * path = [[NSBundle mainBundle] pathForResource:@"Zaikoichi" ofType:@"txt"]; NSError *error; NSStringEncoding encoding; NSString *content = [NSString stringWithContentsOfFile:path encoding:NSMacOSRomanStringEncoding error:&error];
and get a result like this:
"101","çÇìc éOòY","¿∂¿ﬁªÃﬁ€≥","100", "102","êÛìc å‹òY","±ª¿ﬁ∫ﬁ€≥","100", "103","é·ìc ëÂï„","‹∂¿¿ﬁ≤Ωπ","100",
It is return nil when I use this:
NSString * content = [NSString stringWithContentsOfFile:&encoding encoding:NSUTF8StringEncoding error:&error];
From this txt file I want to get a readable NSString. I tried searching but I did not find a solution.In my case, customers do not modify txt file to UTF8 manual. They just copy file to iCloud document , after that my application read this file.
As the text file is in the bundle and you have access to it open it in a text editor and save it UTF8 encoded.
Then read it always with
NSStringEncoding, The following constants are provided by NSString as possible string This is an incomplete list. encoding to the CFStringConvertEncodingToNSStringEncoding function. 8-bit EUC encoding for Japanese text. NSUTF8StringEncoding of exceptions raised if NSString cannot represent a string in a given encoding, The file isn't binary, it is text of some sort, and mostly ASCII. The NSData search routine you showed doesn't really work for me, because I am not looking for a particular string. What I hope to do is display the results of a "grep" UNIX shell call, using NSTask, which returns the results as NSData.
You should put the
stringWithContentsOfFile and not
NSString * content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
The iOS 5 Developer's Cookbook: Expanded Electronic Edition: , encoding, but ObjectiveC supports a large range of options, including ASCII, Japanese, UTF8 encoding can be used safely with ASCII text; UTF8 was explicitly created The request shown here returns a Boolean YES if the string was written, or NO if it was not. Converting Strings to Arrays You can convert a string into. An 8-bit representation of Unicode characters, suitable for transmission or storage by ASCII-based systems.
I resolved my problem by using NSShiftJISStringEncoding
NSString * path = [self getIcloudPathFromFileName:name]; NSError *error; NSStringEncoding encoding; NSString *content = [NSString stringWithContentsOfFile:path encoding:NSShiftJISStringEncoding error:&error];
addingPercentEncoding(withAllowedCharacters:), Entire URL strings cannot be percent-encoded, because each URL component specifies a different set of allowed characters. For example, the query component I google searched a long time but still can't figure this out. I have a UTF-8 format text file with Japanese phrase in it. I tried to use wifsream to read the file into wstring but the string holds some garbage information instead of Japanese. Anyone know how to do this? I am using Win32 API.
utf8_encode - Manual, This function will not convert such Windows-1252 characters correctly. Use a Walk through nested arrays/objects and utf8 encode all strings. <?php I've used this to encode everything from Hebrew to Japanese without problems <? which converts the 512,000 character string in 0.00185 sec. Note that invalid input is still not detected. We can still make it faster by converting the UTF-16 code points "manually" instead of using strtoul(). This is more code, but again faster, and also detects all kinds of invalid input: func dataFromHexString() -> NSData?
Unicode data | Django documentation, In most cases when Django is dealing with strings, it will convert them to strings The iri_to_uri() function will not change ASCII characters that are otherwise How to store text in multiple languages in SQL Server. If you have to store and retrieve characters of any other language besides English in SQL Server, you must do the following – Use a Unicode compatible data type for the table column. NVACHAR, NCHAR, NTEXT are the datatypes in SQL Server that can be used for storing non-English characters.
A.11 MySQL 5.6 FAQ: MySQL Chinese, Japanese, and Korean , What should I do if I want to convert SJIS 81CA to cp932? A.11.6. A.11.13. Why do CJK strings sort incorrectly in Unicode? For example, the gb18030 character set is not supported prior to MySQL 5.7.4. However The utf8 and ucs2 character sets support the characters from Unicode Basic Multilingual Plane (BMP). If you become really comfortable using the Japanese Microsoft IME keyboard, you can set it here as your default so that you don’t have to keep switching to it after you boot up your PC. You can use the IME to type in both Japanese or English as we will see in a bit, so this is a good option to remember.