A C# library that provides a collection of useful string extension methods for common string manipulation and validation tasks. This library consolidates various string utility methods used across different projects into a single, reusable package.
You can install iStringExtensions via NuGet:
Install-Package iStringExtensionsOr using the .NET CLI:
dotnet add package iStringExtensionsIsInteger(): Check if a string represents a valid integerIsNumber(): Check if a string represents a valid number (supports decimal numbers)IsJson(): Validate if a string is valid JSONIsEmail(): Validate email address formatIsIpV4(): Validate IPv4 address format
WrapWithAList(): Convert string to ListWrapWithAnArray(): Convert string to string arrayConsolidateSpaces(): Replace multiple consecutive spaces with a single spaceToMemoryStream(): Convert string to MemoryStream
SplitAsEnumerableOf<T>(): Split string into enumerable of any primitive typeQueryStringToDictionary(): Parse query string into dictionaryRegexMatch(): Perform regex matchingRegexExtract(): Extract matches using regex
GetMd5Hash(): Generate MD5 hash of a stringGetSha1Hash(): Generate SHA1 hash of a string
DeserializeJson<T>(): Deserialize JSON strings into objects
using iStringExtensions;
// Validation examples
bool isInteger = "123".IsInteger(); // true
bool isNumber = "123.45".IsNumber(); // true
bool isValidJson = "{\"name\":\"test\"}".IsJson(); // true
// Transformation examples
List<string> list = "test".WrapWithAList();
string[] array = "test".WrapWithAnArray();
// Parsing examples
var numbers = "1,2,3".SplitAsEnumerableOf<int>(",");
var dictionary = "key1=value1;key2=value2".QueryStringToDictionary();
// Hashing examples
string md5 = "test".GetMd5Hash();
string sha1 = "test".GetSha1Hash();The library includes robust error handling with a custom StringExtensionsException class that is thrown when validation fails or invalid operations are attempted.
The library includes comprehensive unit tests in the UnitTests project using xUnit and FluentAssertions.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.