A library with extension methods to convert strings between common casings used in code.
CaseConverter is a lightweight .NET library that provides a set of extension methods for converting strings between various case styles commonly used in programming. Whether you need to transform identifiers between different naming conventions or format text for display, CaseConverter makes these operations simple and efficient.
- ToTitleCase: Converts text to Title Case (Each Word Capitalized)
- ToPascalCase: Converts text to PascalCase (CapitalizedWords)
- ToCamelCase: Converts text to camelCase (firstWordLowerCaseRestCapitalized)
- ToSnakeCase: Converts text to snake_case (lowercase_with_underscores)
- ToKebabCase: Converts text to kebab-case (lowercase-with-hyphens)
- ToMacroCase: Converts text to MACRO_CASE (UPPERCASE_WITH_UNDERSCORES)
- ToUppercaseFirstChar: Converts only the first character to uppercase (Uppercasefirstchar)
- ToLowercaseFirstChar: Converts only the first character to lowercase (lowercaseFirstChar)
Install-Package ktsu.CaseConverterdotnet add package ktsu.CaseConverter<PackageReferenceInclude="ktsu.CaseConverter"Version="x.y.z" />usingktsu.CaseConverter;stringoriginal="This is a test string";// Convert to different casesstringpascalCase=original.ToPascalCase();// "ThisIsATestString"stringcamelCase=original.ToCamelCase();// "thisIsATestString"stringsnakeCase=original.ToSnakeCase();// "this_is_a_test_string"stringkebabCase=original.ToKebabCase();// "this-is-a-test-string"stringmacroCase=original.ToMacroCase();// "THIS_IS_A_TEST_STRING"Console.WriteLine(pascalCase);Console.WriteLine(camelCase);Console.WriteLine(snakeCase);Console.WriteLine(kebabCase);Console.WriteLine(macroCase);// Working with code identifiersstringvariableName="customer_order_details";stringclassName=variableName.ToPascalCase();// "CustomerOrderDetails"stringpropertyName=variableName.ToCamelCase();// "customerOrderDetails"stringconstantName=variableName.ToMacroCase();// "CUSTOMER_ORDER_DETAILS"// Handling acronyms and special casesstringwithAcronym="API_response_URL";stringpascalWithAcronym=withAcronym.ToPascalCase();// "ApiResponseUrl"// First character transformationsstringsentence="lorem ipsum dolor sit amet";stringcapitalized=sentence.ToUppercaseFirstChar();// "Lorem ipsum dolor sit amet"| Method | Parameters | Return Type | Description |
|---|---|---|---|
ToTitleCase() | None | string | Converts string to Title Case |
ToPascalCase() | None | string | Converts string to PascalCase |
ToCamelCase() | None | string | Converts string to camelCase |
ToSnakeCase() | None | string | Converts string to snake_case |
ToKebabCase() | None | string | Converts string to kebab-case |
ToMacroCase() | None | string | Converts string to MACRO_CASE |
ToUppercaseFirstChar() | None | string | Capitalizes only the first character |
ToLowercaseFirstChar() | None | string | Makes only the first character lowercase |
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to update tests as appropriate and adhere to the existing coding style.
This project is licensed under the MIT License - see the LICENSE.md file for details.