PO8

Rust string length in various units

PO8
Dec 6th, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

To calculate the length of a Rust string s in Unicode code points, use

s.chars().count()

You can calculate the length in grapheme clusters using the unicode-segmentation crate from crates.io. It also does other cool things like words and sentences.

Add Comment
Please, Sign In to add comment