NSString *string = @"??"; const char *c = [string cStringUsingEncoding:NSISOLatin1StringEncoding]; NSString *newString = [[NSString alloc]initWithCString:c encoding:NSUTF8StringEncoding]; NSLog(@"%@",newString); // ü
"Malformed UTF-8 sequence" means a sequence of bytes which are invalid in UTF-8. Your problem is unexpected results after parsing a string with a different encoding than the one used by the original author of the string. Hexadecimal data C3 BC parsed with UTF-8 encoding is character ü . Instead you used Latin-1 encoding, which results in ?? . Then you created a NSString from the Latin-1 parsed string, which means you converted the Latin-1 string to a UTF-16 string (which is the native format of NSString). Representing a given data in different encodings shows up as different chars, but doesn't change the data. Converting to a different encoding does change the data in an attempt to reproduce the same characters. Example: The character ?? is C3 83 C2 BC in UTF-8, but C3 BC in Latin-1. So I converted to the same chars in Latin-1 to get the original data, and then I parsed as UTF-8
|