Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String with literal unicode value to unicode character in Rust

Tags:

rust

So i have a string for example like

"HITMAN\u2122 Free Trial"

is there any way i can convert the \u2122 to an actual unicode character so that the string would look like this

"HITMAN™ Free Trial"

Edit: for clarification the first string is an utf-8 string from an api, and i need to parse it for display

like image 811
DrVilepis Avatar asked Oct 25 '25 09:10

DrVilepis


1 Answers

Just add {and} around 2122, like this:

let unicode_str = "HITMAN\u{2122} Free Trial";
println!("{}", unicode_str);

like image 99
Riton Elion Avatar answered Oct 28 '25 02:10

Riton Elion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!