Skip to content
Discussion options

You must be logged in to vote

Hi! There isn't a built in yet, but something like the following would work for ascii strings:

    use std::string::{Self, String};
    use std::vector;

    public fun to_lowercase(s: &String): String {
        let bytes = string::bytes(s);
        let lowercased_bytes = vector::map_ref<u8, u8>(bytes, |byte| {
            let byte = *byte;
            if (byte >= 65 && byte <= 90) {
                byte + 32
            } else {
                byte
            }
        });
        string::utf8(lowercased_bytes)
    }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 0xmaayan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants