Created
May 15, 2021 00:44
-
-
Save Shaun289/cf5554d20c5846bf5f88e6c0268cd729 to your computer and use it in GitHub Desktop.
Rust UTF-8 String count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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