In Ruby, the len_utf8()
method returns the number of bytes a character would need if encoded in UFT-8. UTF-8 is the most common character encoding. It is popular because it can store text containing characters efficiently.
character.len_uft8()
This method does not take any parameter.
In Rust, the total size of a character is 4 bytes. Hence, the return value is an integer between 1 and 4.
fn main(){// get the number of bytes a character will take if// encoded in UFT-8println!("{}", '9'.len_utf8());println!("{}", 'A'.len_utf8());println!("{}", 'c'.len_utf8());println!("{}", 'ℝ'.len_utf8());println!("{}", '💣'.len_utf8());}
len_utf8()
function to obtain the bytes of some characters which are encoded to UTF-8. Then we print these number of bytes to the console.