Asal.StringExtentions
1.7.0
dotnet add package Asal.StringExtentions --version 1.7.0
NuGet\Install-Package Asal.StringExtentions -Version 1.7.0
<PackageReference Include="Asal.StringExtentions" Version="1.7.0" />
<PackageVersion Include="Asal.StringExtentions" Version="1.7.0" />
<PackageReference Include="Asal.StringExtentions" />
paket add Asal.StringExtentions --version 1.7.0
#r "nuget: Asal.StringExtentions, 1.7.0"
#:package Asal.StringExtentions@1.7.0
#addin nuget:?package=Asal.StringExtentions&version=1.7.0
#tool nuget:?package=Asal.StringExtentions&version=1.7.0
Asal.StringExtentions
A lightweight .NET utility library that provides powerful string extensions and serialization helpers to simplify common development tasks.
📦 Installation
Using .NET CLI
dotnet add package Asal.StringExtentions
Using Package Manager Console
Install-Package Asal.StringExtentions
Using Visual Studio
- Open Manage NuGet Packages
- Search for Asal.StringExtentions
- Click Install
🚀 Usage
After installing the package, import the namespace and call extensions directly on strings:
using Asal.StringExtentions;
var result = "Hello@World!".ClearSpecialCharacters();
✨ Available Extensions
🔤 String Utilities
1. ClearSpecialCharacters(bool replaceWithSpace = false)
Removes special characters from the string.
"Hello@World!".ClearSpecialCharacters();
// Output: "HelloWorld"
2. ClearDigits(bool replaceWithSpace = false)
Removes all digits from the string.
"abc123".ClearDigits();
// Output: "abc"
3. Humanize()
Separates PascalCase or camelCase words.
"HelloWorldTest".Humanize();
// Output: "Hello World Test"
4. IsValidEmail()
Checks if the string is a valid email address.
"test@mail.com".IsValidEmail(); // true
5. ExtractEmails()
Extracts all valid emails from a string.
var text = "Contact admin@test.com or support@domain.com";
var emails = text.ExtractEmails();
📄 JSON Extensions
6. ExtractJsonPropertyValue(string jsonProperty)
Extracts a property value from a JSON string using path syntax.
var json = "{\"name\":\"John\",\"age\":30}";
var result = json.ExtractJsonPropertyValue<string>("name");
// Output: "John"
Nested example:
var json = "{\"data\":[{\"baseObject\":{\"name\":\"test\",\"age\":25}}]}";
var age = json.ExtractJsonPropertyValue<int>("data[0].baseObject.age");
// Output: 25
Extract object:
var obj = json.ExtractJsonPropertyValue<object>("data[0].baseObject");
7. TryExtractJsonPropertyValue(string jsonProperty, out T result)
Safe extraction without throwing exceptions.
var success = json.TryExtractJsonPropertyValue<int>("data[0].baseObject.age", out var age);
// success = true, age = 25
8. ExtractJsonArrayPropertyValue(string jsonProperty)
Extracts array values as IEnumerable<T>.
var json = "{\"cars\":[\"Ford\",\"BMW\",\"Fiat\"]}";
var cars = json.ExtractJsonArrayPropertyValue<string>("cars");
// ["Ford", "BMW", "Fiat"]
Supports:
- Primitive arrays
- Nested arrays
- JSONPath style queries (
items[*].id)
🔄 XML / JSON / YAML Converters
9. XmlToJson()
Converts XML string to JSON.
var xml = "<root><name>Hamza</name></root>";
var json = xml.XmlToJson();
10. JsonToXml()
Converts JSON string to XML.
⚠️ Behavior Change (v1.7.0)
JsonToXml() no longer wraps the output automatically with a default <root> element.
If JSON already contains a root:
var json = "{\"root\":{\"name\":\"Hamza\"}}";
var xml = json.JsonToXml(); // Correct round-trip
If JSON has no root:
var json = "{\"name\":\"Hamza\"}";
var xml = json.JsonToXml("root"); // Explicit wrapping
Parameters:
deserializeRootElementName(optional)writeArrayAttribute(default: false)encodeSpecialCharacters(default: false)
11. YamlToJson()
Converts YAML string to JSON.
var yaml = "Id: 1\nName: Test";
var json = yaml.YamlToJson();
12. JsonToYaml()
Converts JSON string to YAML.
var yaml = json.JsonToYaml();
🧩 Case Conversion Extensions
13. Slugify()
Creates SEO-friendly slugs.
"Café Déjà Vu Example".Slugify();
// "cafe-deja-vu-example"
14. ToCamelCase()
"hello world".ToCamelCase(); // "helloWorld"
15. ToPascalCase()
"hello world".ToPascalCase(); // "HelloWorld"
16. ToSnakeCase()
"hello world".ToSnakeCase(); // "hello_world"
17. ToKebabCase()
"hello world".ToKebabCase(); // "hello-world"
🔐 Security Utility
18. CalculateMD5Checksum()
Generates an MD5 hash for the input string.
var checksum = "hello world".CalculateMD5Checksum();
// "5eb63bbbe01eeed093cb22bb8f5acdc3"
⚡ Improvements in v1.7.0
- Centralized compiled Regex patterns (better performance)
- Improved JSON array extraction (supports primitives & complex objects)
- Nullable safety and reliability improvements
- Cleaner and optimized internal implementation
📊 Milestone
🎉 Over 4,500+ downloads on NuGet!
Thank you for your support 🙏
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.9)
- Newtonsoft.Json (>= 13.0.4)
- YamlDotNet.NetCore (>= 1.0.0)
-
net6.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.9)
- Newtonsoft.Json (>= 13.0.4)
- YamlDotNet.NetCore (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Improvements and behavioral adjustments:
- Introduced centralized compiled RegexPatterns for better performance
- Improved JSON array extraction to support both primitive and object tokens
- Fixed nullable warnings in JSON helper methods
- Code cleanup and reliability improvements
Behavioral Change:
- JsonToXml() no longer wraps the result in a default root element automatically.
Pass a root name explicitly if wrapping is required.