Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Created May 15, 2021 00:44
Show Gist options
  • Save Shaun289/cf5554d20c5846bf5f88e6c0268cd729 to your computer and use it in GitHub Desktop.
Save Shaun289/cf5554d20c5846bf5f88e6c0268cd729 to your computer and use it in GitHub Desktop.
Rust UTF-8 String count
// My first rust program
// UTF-8 character count vs bytes length
// https://shaun289.github.io/2021-05-14-rust_stringlength/
fn string_length(s: &String) -> usize {
s.chars().count()
}
fn main() {
println!("Hello, world!");
let s = String::from("테스트");
println!("{} utf-8 length : {} string length : {} ", s, string_length(&s), s.len());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment