-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pedro Ferreira
committed
Jan 30, 2025
1 parent
eeb051c
commit 88f8eb6
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## strings | ||
|
||
### Instructions | ||
|
||
Create a **function** which receives a string slice and returns the number of characters in that 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 | ||
$ cargo run | ||
length of ❤ = 1 | ||
length of 形声字 = 3 | ||
length of change = 6 | ||
length of 😍 = 1 | ||
$ | ||
``` |