1

I'm creating an app for to sending messages from one user to another user.

This app is developed in Android and iOS (swift 2.2).

In Android I'm using org.apache.commons to encode / decode string to Unicode using StringEscapeUtils.escapeJava and StringEscapeUtils.unescapeJava Encoding method gave me this result (for a string containing emojis) :

Hello \uD83E\uDD23

This is impossible to decode this in Swift.

According to this post, I think iOS need this String as input to correct decode it :

Hello \u{D83E}\u{DD23}

Is there an easy way to make iOS and Android compatible ?

Community
  • 1
  • 1
Florian Mac Langlade
  • 1,863
  • 7
  • 28
  • 57

1 Answers1

1

Found solution :

static func decode(input: String) -> String? {
    let ns = NSString(string: input)
    let data:NSData = ns.dataUsingEncoding(NSUTF8StringEncoding)!

    return NSString(data:data,encoding:NSNonLossyASCIIStringEncoding) as? String
}
Florian Mac Langlade
  • 1,863
  • 7
  • 28
  • 57