Zakira.Imprint.Sample - String Utilities
This skill teaches you how to use the Zakira.Imprint.Sample NuGet package, which provides string manipulation utilities via the StringExtensions and StringHelper classes.
Namespace
All types are in the Zakira.Imprint.Sample.WithCode namespace:
using Zakira.Imprint.Sample.WithCode;
StringExtensions (Extension Methods)
These are extension methods on string. After adding the using directive, call them directly on any string instance.
Slugify
Converts a string to a URL-friendly slug (lowercase, hyphens, no special chars).
"Hello World! This is C#".Slugify() // => "hello-world-this-is-c"
"Café Résumé".Slugify() // => "cafe-resume" (diacritics removed)
" Multiple Spaces ".Slugify() // => "multiple-spaces"
Truncate
Truncates to a maximum length with a configurable suffix.
"Hello World".Truncate(8) // => "Hello..."
"Hello World".Truncate(8, "~") // => "Hello W~"
"Hi".Truncate(10) // => "Hi" (no truncation needed)
Mask
Masks the middle portion of a string, keeping visible characters at start and end.
"1234567890".Mask(2, 2) // => "12******90"
"SensitiveData".Mask(3, 3) // => "Sen*******ata"
"1234567890".Mask(2, 2, '#') // => "12######90"
ToTitleCase
Converts to Title Case (first letter of each word capitalized).
"hello world example".ToTitleCase() // => "Hello World Example"
"ALL CAPS INPUT".ToTitleCase() // => "All Caps Input"
RemoveDiacritics
Strips accent marks from characters.
"café résumé".RemoveDiacritics() // => "cafe resume"
"naïve über".RemoveDiacritics() // => "naive uber"
ToCamelCase
Converts to camelCase from any word-separated format.
"hello world example".ToCamelCase() // => "helloWorldExample"
"some-kebab-case".ToCamelCase() // => "someKebabCase"
"SOME_SCREAMING_SNAKE".ToCamelCase() // => "someScreamingSnake"
ToSnakeCase
Converts to snake_case.
"Hello World".ToSnakeCase() // => "hello_world"
"camelCaseExample".ToSnakeCase() // => "camel_case_example"
"PascalCaseInput".ToSnakeCase() // => "pascal_case_input"
Reverse
Reverses the characters in a string.
"Hello".Reverse() // => "olleH"
"12345".Reverse() // => "54321"
WordCount
Counts the number of whitespace-separated words.
"Hello world, this is a test".WordCount() // => 6
" ".WordCount() // => 0
StringHelper (Static Methods)
These are static methods. Call them via StringHelper.MethodName(...).
MaskEmail
Smart email masking that preserves the domain.
StringHelper.MaskEmail("john.doe@example.com") // => "jo******@example.com"
StringHelper.MaskEmail("ab@test.com") // => "ab@test.com" (too short to mask)
StringHelper.MaskEmail("admin@corp.com", 3) // => "adm**@corp.com"
MaskCreditCard
Masks all but the last 4 digits of a credit card number, re-formatted with hyphens.
StringHelper.MaskCreditCard("4111-1111-1111-1111") // => "****-****-****-1111"
StringHelper.MaskCreditCard("4111111111111111") // => "****-****-****-1111"
ShortHash
Generates a deterministic short hash (MD5-based hex) for a string input.
StringHelper.ShortHash("hello world") // => "5eb63bbb" (8 chars, default)
StringHelper.ShortHash("hello world", 12) // => "5eb63bbbe01e" (12 chars)
Use cases: cache keys, deduplication tokens, short identifiers.
GenerateRandom
Generates a random alphanumeric string of the desired length.
StringHelper.GenerateRandom(12) // => e.g. "aB3xK9mP2qLw"
StringHelper.GenerateRandom(6, "0123456789") // => e.g. "384729" (digits only)
IsValidEmail
Basic email format validation.
StringHelper.IsValidEmail("user@example.com") // => true
StringHelper.IsValidEmail("not-an-email") // => false
StringHelper.IsValidEmail("") // => false
GetInitials
Extracts uppercase initials from a name.
StringHelper.GetInitials("John Michael Doe") // => "JMD"
StringHelper.GetInitials("Alice") // => "A"
StringHelper.GetInitials("A B C D E", 2) // => "AB" (max 2 initials)
Common Patterns
Preparing user-generated content for URL slugs
var title = "My Blog Post: A Café Story!";
var slug = title.Slugify(); // => "my-blog-post-a-cafe-story"
var url = $"/posts/{slug}";
Displaying masked sensitive data in logs
var email = "customer@company.com";
var card = "4111-1111-1111-1111";
Console.WriteLine($"Email: {StringHelper.MaskEmail(email)}");
Console.WriteLine($"Card: {StringHelper.MaskCreditCard(card)}");
Converting between naming conventions
var input = "myPropertyName";
var snake = input.ToSnakeCase(); // => "my_property_name"
var camel = snake.ToCamelCase(); // => "myPropertyName"
var slug = input.Slugify(); // => "my-property-name" (kebab-like)
Error Handling
- All extension methods handle
nulland empty strings gracefully (return empty string or the input). TruncatethrowsArgumentOutOfRangeExceptionifmaxLength < 0.MaskthrowsArgumentOutOfRangeExceptionifvisibleStartorvisibleEndare negative.ShortHashthrowsArgumentNullExceptionif input is null, andArgumentOutOfRangeExceptionif length is out of range.
Source Package
- Package: Zakira.Imprint.Sample
- Installed Via: NuGet (provides both the DLL and these skill files)
- Skill Location:
.github/skills/