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 and efficient C# library designed to simplify string manipulation and validation. It provides robust utilities for converting strings to various casing styles, validating common data formats, and, with the addition of the MatchON namespace, enables advanced string similarity comparisons.
Convert strings into the following popular casing formats:
snake_casekebab-casePascalCasecamelCaseSentence caseTitle CaseExtensive helper methods to validate common string formats:
With the new MatchON namespace, CaseON adds several advanced string similarity algorithms:
ArgumentExceptions for null or empty/whitespace input strings.New MatchON Namespace:
MatchON that includes advanced string similarity matching algorithms to compare strings with greater accuracy. The following methods are now available:
String Validation Methods:
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 Casing
string myString = "This Is A Test String";
string snakeCase = CaseON.ConvertON.ToSnakeCase(myString); // Output: this_is_a_test_string
string kebabCase = CaseON.ConvertON.ToKebabCase(myString); // Output: this-is-a-test-string
string pascalCase = CaseON.ConvertON.ToPascalCase(myString); // Output: ThisIsATestString
string camelCase = CaseON.ConvertON.ToCamelCase(myString); // Output: thisIsATestString
string sentenceCase = CaseON.ConvertON.ToSentenceCase(myString); // Output: This is a test string
string titleCase = CaseON.ConvertON.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}");
string email = "test@example.com";
string url = "https://www.example.com";
string ipAddress = "192.168.1.1";
string phoneNumber = "+1234567890";
string postalCode = "90210";
string date = "2024-11-26";
bool isValidEmail = CaseON.ValidateON.IsValidEmail(email); // Output: true
bool isValidUrl = CaseON.ValidateON.IsValidUrl(url); // Output: true
bool isValidIp = CaseON.ValidateON.IsValidIPv4(ipAddress); // Output: true
bool isValidPhone = CaseON.ValidateON.IsValidPhoneNumber(phoneNumber); // Output: true
bool isValidPostal = CaseON.ValidateON.IsValidPostalCode(postalCode); // Output: true
bool isValidDate = CaseON.ValidateON.IsValidDate(date); // Output: true
Console.WriteLine($"Valid Email: {isValidEmail}");
Console.WriteLine($"Valid URL: {isValidUrl}");
Console.WriteLine($"Valid IP Address: {isValidIp}");
Console.WriteLine($"Valid Phone Number: {isValidPhone}");
Console.WriteLine($"Valid Postal Code: {isValidPostal}");
Console.WriteLine($"Valid Date: {isValidDate}");
// String Similarity Matching with MatchON
string string1 = "hello world";
string string2 = "hello wrld";
double levenshteinSimilarity = MatchON.GetSimilarity(string1, string2); // Similarity based on Levenshtein Distance
double jaroWinklerSimilarity = MatchON.GetJaroWinklerSimilarity(string1, string2); // Similarity based on Jaro-Winkler
double lcsSimilarity = MatchON.GetLcsSimilarity(string1, string2); // Similarity based on Longest Common Subsequence
Console.WriteLine($"Levenshtein Similarity: {levenshteinSimilarity}"); // Output: Similarity score between 0 and 1
Console.WriteLine($"Jaro-Winkler Similarity: {jaroWinklerSimilarity}"); // Output: Similarity score between 0 and 1
Console.WriteLine($"LCS Similarity: {lcsSimilarity}"); // Output: Similarity score between 0 and 1