How to trim null bytes from String?

Hi. everyone!

let nft_type = match &nft_name[..] {
    "Primitive" => Some(0),
    "Uncommon" => Some(1),
    "Rare" => Some(2),
    "Legendary" => Some(3),
    _ => None

Here, nft_name is String.
The result of &nft_name[..] is

So the match result is None
How can I get "Primitive" ?

Try trim_end_matches:

let nft_type = match nft_name.trim_end_matches('\0') {
    /* ... */


1 Like


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.