I am developing one chat application, for that everything is working fine except. This application is in both Android and iOS platform. We want to pass emoji in the chat. In android we use UTF encoding with StringEscapeUtils
. it is working perfect in android. when we pass emoji it is encoded and stored in DB like "\u263A".
Now in android this string is also decode and shown perfect in view but some how we can not decode the same string in iOS. We have simply try to decode using UTF string. But still it is not working.
I have already follow this link Print unicode character from variable (swift)
Thanks in advance.
The easiest way is to use CFStringTransform like below.
let wI = NSMutableString( string: "\\u263a" )
CFStringTransform( wI, nil, "Any-Hex/Java" as NSString, true )
someUILabel.text = wI as String
You should try this:
For 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 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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With