Why does he directly comment on an encoded string that does not convert to Arabic?

NSString * string = @"ุงุงู„ู’ุญูŽู…ู’ุฏู ู„ูู„ูŽู‘ู‡ู ุฑูŽุจูู‘ ุงู„ู’ุนูŽุงู„ูŽู…ููŠู†ูŽ"; const char *c = [string cStringUsingEncoding:NSUTF8StringEncoding]; NSString *newString = [[NSString alloc]initWithCString:c encoding:NSISOLatin1StringEncoding]; NSLog(@"%@",newString); // NSString * staticEncodedString = @"ร˜ยงร™ร™ร˜ร™ร™ ร™ร˜ยฏร™ ร™ร™ร™ร™ร™ร™ร™ ร˜ยฑร™ร˜ยจร™ร™ ร˜ยงร™ร™ร˜ยนร™ร˜ยงร™ร™ร™ ร™ร™ร™ร™"; const char *cvvv = [newString cStringUsingEncoding:NSISOLatin1StringEncoding]; NSString *newStringV = [[NSString alloc]initWithCString:cvvv encoding:NSUTF8StringEncoding]; NSLog(@"%@",newStringV); 

Why is this directly commented on? Does the encoded string not convert to Arabic? When I hardcode the Arabic language, it encodes and then decodes correctly, but why is the static encoded string not readable in Arabic?

Thanks for your reply Jake. Yes, I am losing data when decoding "staticEncodedString". But all I want is to decode the next line in Arabic.

  NSString * staticEncodedString = @"ร˜ยงร™ร™ร˜ร™ร™ ร™ร˜ยฏร™ ร™ร™ร™ร™ร™ร™ร™ ร˜ยฑร™ร˜ยจร™ร™ ร˜ยงร™ร™ร˜ยนร™ร˜ยงร™ร™ร™ ร™ร™ร™ร™"; 
+4
source share
2 answers

Encoding happens in ANSI, I think change it to UTF-8 from any tool. Use Notepad ++ for application, for example, and then you can use encoding in sqlite or ios.

+4
source

Latin1 cannot represent Arabic characters, so you cannot encode this string to Latin1. Arabic refers to the Latin4 character set. The cStringUsingEncoding method returns null if the string cannot be losslessly encoded into the specified encoding.

Why do you want to encode the Arabic string in LatinX? UTF-8 is likely to be the best performance as it uses only standard characters and a simple approach without headaches. This may take a little more byte than Latin4, but in most cases it will be worth it.

Converting to Latin1 will result in loss of text.

+1
source

All Articles