-1

I am trying to decode a string which is in UTF-8 format, into normal human readable string and tried may codes available on SO. But non of these worked.

My demo UTF-8 String is :-

let demoString: String = "यॠपहलॠपहलॠà¤à¤¾à¤¹à¤¤à¤¯à¥ बहà¤à¥ बहà¤à¥ हालत"

Is there is anyway to decode this UTF-8 String in swift. Any help would be appricated.

Himanshu
  • 2,832
  • 4
  • 23
  • 51
  • What do you mean by decode ? The string is the characters you see. – navid Sep 05 '16 at 10:56
  • this is in utf-8 encode format, it is hindi sentence in normal format – Himanshu Sep 05 '16 at 11:01
  • Decoding it with NSUnicodeStringEncoding gives a result but it doesn't look like Hindi? I'm not sure. – Eric Aya Sep 05 '16 at 11:05
  • What is the source of the string? This is UTF-8 decoded as if it was some variant of ISO-8859, but if it has been properly decoded in the first place it would show up correctly. – jcaron Sep 05 '16 at 11:05
  • It is slightly broken, though, what looks like `ॠ` (`e0 a5 20`) is of course not valid UTF-8. – jcaron Sep 05 '16 at 11:08
  • Can't you just write the string? e.g. `let hello = "नमस्ते"` – Matt Le Fleur Sep 05 '16 at 11:29
  • 1
    Himanshu cross check your string it doesn't appears to be an NSUTF-8 encoded string. I have verified that it's not UTF-8 encoded at following online tool https://mothereff.in/utf-8 – Pankaj Yadav Sep 05 '16 at 11:38
  • I agree, your string should be more in the format `let str = "\u{0906}\u{092A}"` etc. – Matt Le Fleur Sep 05 '16 at 11:43

1 Answers1

2
let demoString: String = "यॠपहलॠपहलॠà¤à¤¾à¤¹à¤¤à¤¯à¥ बहà¤à¥ बहà¤à¥ हालत"

This defines a perfectly fine string containing some rather weird characters like "à", "¤" and so on. There is no decoding that can be done here. The first character is a "Latin Small Letter A With Grave", U+00E0 or C3A0 in UTF-8 format.

If you want a string with "Hindi" characters - I suppose you mean Devanagari, or Bengali, Gurmukhi, Gujarati etc. , type for example

let demoString: String = "ऄइउऋऌऍ"
gnasher729
  • 51,477
  • 5
  • 75
  • 98