Skip to content

camel_case

Converts s to camelCase.

Words are split on any non-alphanumeric character and on case boundaries; an embedded run of capitals is an acronym, so only its last letter starts the next word (userID becomes userId).

use helpers4::string::camel_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 camel_case(s: &str) -> String
ParameterTypeDescription
s&strThe text to convert.

String

use helpers4::string::camel_case;

assert_eq!(camel_case("hello-world"), "helloWorld");
assert_eq!(camel_case("user_name"), "userName");
assert_eq!(camel_case("userID"), "userId");
assert_eq!(camel_case(""), "");

src/string/camel_case.rs