The CaseON library includes MatchON, ConvertON, and ValidateON classes for string casing, conversion, and validation in C# applications.
$ dotnet add package CaseONCaseON is a lightweight C# library providing a simple and efficient way to convert strings to various casing styles. It handles different separators and offers robust error handling.
snake_casekebab-casePascalCasecamelCaseSentence caseTitle CaseArgumentExceptions for null or empty/whitespace input strings. Handles strings containing spaces, underscores, and hyphens.Installation: You can easily add CaseON to your project via NuGet. Alternatively, you can directly include the source code in your project.
Basic Example:
using CaseON;
string myString = "This Is A Test String";
string snakeCase = StringFormatter.ToSnakeCase(myString); // Output: this_is_a_test_string
string kebabCase = StringFormatter.ToKebabCase(myString); // Output: this-is-a-test-string
string pascalCase = StringFormatter.ToPascalCase(myString); // Output: ThisIsATestString
string camelCase = StringFormatter.ToCamelCase(myString); // Output: thisIsATestString
string sentenceCase = StringFormatter.ToSentenceCase(myString); // Output: This is a test string
string titleCase = StringFormatter.ToTitleCase(myString); // Output: This Is A Test String
Console.WriteLine($"Snake Case: {snakeCase}");
Console.WriteLine($"Kebab Case: {kebabCase}");
Console.WriteLine($"Pascal Case: {pascalCase}");
Console.WriteLine($"Camel Case: {camelCase}");
Console.WriteLine($"Sentence Case: {sentenceCase}");
Console.WriteLine($"Title Case: {titleCase}");
CaseON throws an ArgumentException if you pass a null or empty/whitespace string to any of its methods. Make sure to handle this exception appropriately in your code:
try
{
string result = StringFormatter.ToSnakeCase(null);
}
catch (ArgumentException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}The StringFormatter class contains the following static methods:
ToSnakeCase(string input): Converts a string to snake_case.ToKebabCase(string input): Converts a string to kebab-case.ToPascalCase(string input): Converts a string to PascalCase.ToCamelCase(string input): Converts a string to camelCase.ToSentenceCase(string input): Converts a string to Sentence case.ToTitleCase(string input): Converts a string to Title Case.