Skip to content

title_case

Capitalizes the first letter of every whitespace-separated word and lowercases the rest.

Whitespace is kept as it is. Only whitespace starts a new word, so it's becomes It's and well-known becomes Well-known. Use pascal_case to also drop the separators.

use helpers4::string::title_case;

Cargo feature string (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features string

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["string"] }
pub fn title_case(s: &str) -> String
ParameterTypeDescription
s&strThe text to convert.

String

use helpers4::string::title_case;

assert_eq!(title_case("the quick brown fox"), "The Quick Brown Fox");
assert_eq!(title_case("HELLO wORLD"), "Hello World");
assert_eq!(title_case("it's"), "It's");

src/string/title_case.rs