I'm working on an app where I get data from an API and I'm getting a Chinese characters like that
"u9c9cu82b1u548cu7231"
it should be like this 鲜花和爱
How can I convert it?
Your string is in escaped unicode format. If it is always in this format you can simply strip out the escaping U characters and convert the hex to code points.
var original = 'u9c9cu82b1u548cu7231';
// split on 'u' and remove the first empty element
var parts = original.split('u')..removeAt(0);
// map from hex string to code point int, and create string
print(String.fromCharCodes(
parts.map<int>((hex) => int.parse(hex, radix: 16)),
));
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