You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
## strings
|
|
|
|
|
|
|
|
### Instructions
|
|
|
|
|
|
|
|
Write a **function** which receives a string slice and returns the number of characters of the string.
|
|
|
|
|
|
|
|
### Expected Function
|
|
|
|
|
|
|
|
```rust
|
|
|
|
pub fn char_length(s: &str) -> usize {
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
|
|
Here is a program to test your function.
|
|
|
|
|
|
|
|
```rust
|
|
|
|
use strings::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("length of {} = {}", "❤", char_length("❤"));
|
|
|
|
println!("length of {} = {}", "形声字", char_length("形聲字"));
|
|
|
|
println!("length of {} = {}", "change", char_length("change"));
|
|
|
|
println!("length of {} = {}", "😍", char_length("😍"));
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
And its output
|
|
|
|
|
|
|
|
```console
|
|
|
|
student@ubuntu:~/[[ROOT]]/test$ cargo run
|
|
|
|
length of ❤ = 1
|
|
|
|
length of 形声字 = 3
|
|
|
|
length of change = 6
|
|
|
|
length of 😍 = 1
|
|
|
|
student@ubuntu:~/[[ROOT]]/test$
|
|
|
|
```
|