Search code examples
iosutf-8arabiclatin1

Why is it direct commented Encoded string not converting 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 it direct commented Encoded string not converting to Arabic? When i hardcode the Arabic it encodes and then decodes correctly, but why can't static encoded string not readable in arabic?

Thanks for your reply Jake. Yes I loose data while decoding the "staticEncodedString".But All I want is to decode the following string back to Arabic.

 NSString * staticEncodedString = @"اÙÙØ­ÙÙ Ùد٠ÙÙÙÙÙÙ٠رÙبÙ٠اÙÙعÙاÙÙÙ ÙÙÙÙ";

Solution

  • The encode is in ANSI i think change it to UTF-8 from any tool. Use Notepad++ to apply for example and then you can use encode it within sqlite or ios.