PowerUtils.Text
Helpers, extensions and utilities for manipulating
Support to
- .NET 3.1 or more
- .NET Framework 4.6.2 or more
- .NET Standard 2.0 or more
How to use
Install NuGet package
This package is available through Nuget Packages: https://www.nuget.org/packages/PowerUtils.Text
Nuget
Install-Package PowerUtils.Text
.NET CLI
dotnet add package PowerUtils.Text
TextExtensions
string.CleanExtraSpaces();
Clean extra spaces. Replace tabs to one space and double spaces to one space
// result = "Hello world!!!"
var result = " Hello world!!! ".CleanExtraSpaces();
string.CleanExtraLineBreak();
Clean extra line breaks. Replace double line breaks to one line break
// result = "Hello\r\nWorld!!!"
var result = "Hello\r\n\r\n\r\nWorld!!!".CleanExtraLineBreak();
string.CleanExtraLineBreakAndLineBreak();
Clean extra spaces, override tabs to one space, double spaces to one space and double line breaks to one line break
// result = "Hello\r\nWorld!!!"
var result = " Hello \r\n\r\n\r\n World!!! ".CleanExtraLineBreakAndLineBreak();
string.EmptyOrWhiteSpace();
Convert a string with empty or white spaces to null
// result = null
var result = " ".EmptyOrWhiteSpace();
string.CompressText(maxLength);
Compress text if greater the max length
// result = "Hell..."
var result = "Hello world!!!".CompressText(5);
string.Truncate(maxLength);
Truncate text if greater the max length
// result = "Hello"
var result = "Hello world!!!".Truncate(5);
string.CapitalizeName();
Capitalize the people amd company names
// result = "Nelson Nobre"
var result = "nelson nobre".CapitalizeName();
string.CleanSpecialCharacters(substitute = "");
Capitalize the people amd company names
// result1 = "HelloWorld"
var result1 = "Hello World!!!".CleanSpecialCharacters();
// result2 = "Hello-World"
var result2 = "Hello World".CleanSpecialCharacters("-");
string.UppercaseFirst();
Uppercase the first character
// result = "Hello world!!!"
var result = "hello world!!!".UppercaseFirst();
string.LowercaseFirst();
Uppercase the first character
// result = "hello world!!!"
var result = "Hello world!!!".UppercaseFirst();
string.ToSnakeCase();
Convert a text to snake case format
// result = "test_snake_case"
var result = "TestSnakeCase".ToSnakeCase();
TextExtensions
string.IsEmail();
Check if the input is an email
// result = true
var result = "nelson@fake.com".IsEmail();
string.CombineURL();
Check if the input is an email
// result = http://localhost:8080/clients/photos
var result = "http://localhost:8080".CombineURL("clients", "photos");
object.ToQueryString();
Convert an object to a QueryString.
(Does not supported in .NET Framework 4.6.2 and .NET Framework 4.8)
object parameters = new
{
Name = "Nelson",
Age = 12,
IsValide = true
};
// result = ?Name=Nelson&Age=12&IsValide=True
var result = parameters.ToQueryString();
⚠️ Warning
Discontinued the extension string.EmptyOrWhiteSpace()
. New method string.EmptyOrWhiteSpaceToNull()
will be removed in 2022/08/31.
Contribution
If you have any questions, comments, or suggestions, please open an issue or create a pull request