How do I capitalize all the characters in a string in Rust?

rust

Solution

I don't think there's any function to do it directly, but you can use the functions in the `UnicodeChar` trait with `chars` and `map` like:

let str = "hello øåÅßç";
let up = str.chars().map(|c| c.to_uppercase()).collect::<String>();
println!("{}", up);

Output:

HELLO ØÅÅßÇ

Tested on `rustc 0.13.0-dev (66601647c 2014-11-27 06:41:17 +0000)`

Problem

There's an answer here for how to capitalize the ASCII characters in a string. This is not quite adequate for my specific problem.

Original source