I have some NSData that may or may not contain invalid UTF-8, but any parts of it that are valid UTF-8 should be interpreted as such. If I use [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]
, it just returns nil
if the data has invalid UTF-8 anywhere. How can I get it to replace the invalid UTF-8 with �, like TextEncoder does?
Asked
Active
Viewed 119 times
0

tbodt
- 16,609
- 6
- 58
- 83
-
You'd probably have to write your own "decoder". – matt Dec 23 '20 at 01:42
-
Its been done before https://stackoverflow.com/questions/30372870/string-from-nsinputstream-is-not-valid-utf8-how-to-convert-to-utf8-more-lossy – skaak Dec 23 '20 at 12:10