How to decode Unicode characters in fast 3?

I am developing one chat application because everything works fine except. This application is located on the Android and iOS platforms. We want to send emozy in the chat. In android, we use UTF encoding with StringEscapeUtils . It works great on Android. when we pass emoji enter image description here it is encoded and stored in DB as "\ u263A".

Now in android this line is also decoded and shown perfectly, but some, like we cannot decode the same line in iOS. We are just trying to decode using a UTF string. But still it does not work.

I already go to this link Printing a Unicode character from a variable (fast)

Thanks in advance.

+5
source share
2 answers

The easiest way is to use CFStringTransform as shown below.

 let wI = NSMutableString( string: "\\u263a" ) CFStringTransform( wI, nil, "Any-Hex/Java" as NSString, true ) someUILabel.text = wI as String 
+4
source

You should try the following:

Example:

 let charString = "263A" if let charCode = UInt32(charString, radix: 16),let unicode = UnicodeScalar(charCode) { let str = String(unicode) print(str) } else { print("invalid input") } 

If you want to print on a Label / TextField, then:

 let charString = "263A" if let charCode = UInt32(charString, radix: 16),let unicode = UnicodeScalar(charCode) { let str = String(unicode) CharLabel.text = str //Print on Label CharTextField.text = str //Print on TextField } else { print("invalid input") } 
+4
source

Source: https://habr.com/ru/post/1260964/


All Articles