Skip to main content
Version: 4.0 (next)

Humanizer.StringHumanizeExtensions

StringHumanizeExtensions Class

Contains extension methods for humanizing string values.

public static class StringHumanizeExtensions

Inheritance System.Object → StringHumanizeExtensions

Methods

StringHumanizeExtensions.Humanize(this string) Method

Transforms a string into a human-readable format by intelligently handling PascalCase, camelCase, underscored_strings, and dash-separated-strings, converting them into space-separated text with appropriate capitalization.

public static string Humanize(this string input);

Parameters

input System.String

The string to be humanized. Must not be null.

Returns

System.String
A humanized version of the input string with spaces inserted between words and appropriate capitalization. Preserves all-uppercase acronyms unless registered with different canonical casing.

Example

"PascalCaseInputString".Humanize() => "Pascal case input string"
"Underscored_input_String_is_turned_INTO_sentence".Humanize() => "Underscored input String is turned INTO sentence"
"dash-separated-string".Humanize() => "Dash separated string"
"HTML".Humanize() => "HTML"
Vocabularies.Default.AddAcronym("iOS");
"IOS".Humanize() => "iOS"
"camelCaseText".Humanize() => "Camel case text"
"Rock&Roll".Humanize() => "Rock & roll"

Remarks

The method applies several rules in order: - If the entire input is uppercase (an acronym), it returns unchanged unless it matches a registered acronym - Handles freestanding underscores/dashes (e.g., "some _ string") - Splits on underscores and dashes - Breaks up PascalCase and camelCase text - Preserves ampersands as separate tokens in PascalCase and camelCase inputs Registered acronyms use their canonical casing. Otherwise, if the result begins with a letter, that letter is capitalized.

StringHumanizeExtensions.Humanize(this string, LetterCasing) Method

Transforms a string into a human-readable format and applies the specified letter casing.

public static string Humanize(this string input, Humanizer.LetterCasing casing);

Parameters

input System.String

The string to be humanized. Must not be null.

casing LetterCasing

The desired letter casing to apply to the humanized result.

Returns

System.String
A humanized version of the input string with the specified casing applied.

Example

"PascalCaseInputString".Humanize(LetterCasing.AllCaps) => "PASCAL CASE INPUT STRING"
"PascalCaseInputString".Humanize(LetterCasing.LowerCase) => "pascal case input string"
"PascalCaseInputString".Humanize(LetterCasing.Title) => "Pascal Case Input String"

Remarks

This is a convenience method that combines Humanize(this string) with ApplyCase(this string, LetterCasing).