Logo

Programming-Idioms

History of Idiom 169 > diff from v41 to v42

Edit summary for version 42 by glmdgrielson:
New Rust implementation by user [glmdgrielson]

Version 41

2018-04-23, 23:14:10

Version 42

2018-05-21, 23:13:46

Idiom #169 String length

Assign to integer n the number of characters of string s.

This can be different from the number of bytes of s.

Illustration

Idiom #169 String length

Assign to integer n the number of characters of string s.

This can be different from the number of bytes of s.

Illustration
Extra Keywords
size
Extra Keywords
size
Code
let n = s.chars().count();
Comments bubble
This is kind of roundabout because the default len method gives bytes, not characters.
Doc URL
https://doc.rust-lang.org/std/str/struct.Chars.html