std-method
char::len_utf8
Find how many UTF-8 bytes a scalar requires, from one to four. Expected stdout (not executed): 1 2 4 Common mistake: Using the result as the number of visible letters.
Formal Syntax & Structure
rust syntaxrust
fn len_utf8(self) -> usizeWorking Example
Example Snippetrust
fn main() { println!("{} {} {}", 'A'.len_utf8(), 'ش'.len_utf8(), '😀'.len_utf8());}