Helpers, extensions and utilities for manipulating strings
- Support to
- How to use
- Install NuGet package
- TextExtensions
- string.CleanExtraSpaces();
- string.CleanExtraLineBreak();
- string.CleanExtraLineBreakAndLineBreak();
- string.EmptyOrWhiteSpaceToNull();
- string.CompressText(maxLength);
- string.Truncate(maxLength);
- string.CapitalizeName();
- string.CleanSpecialCharacters(substitute = "");
- string.UppercaseFirst();
- string.LowercaseFirst();
- string.ToSnakeCase();
- TextExtensions
- Contribution
- .NET 9.0
- .NET 8.0
- .NET 7.0
- .NET 6.0
- .NET 5.0
- .NET 3.1
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
Clean extra spaces. Replace tabs to one space and double spaces to one space
// result = "Hello world!!!"
var result = " Hello world!!! ".CleanExtraSpaces();
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();
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();
Convert a string with empty or white spaces to null
// result = null
var result = " ".EmptyOrWhiteSpaceToNull();
Compress text if greater the max length
// result = "Hell..."
var result = "Hello world!!!".CompressText(5);
Truncate text if greater the max length
// result = "Hello"
var result = "Hello world!!!".Truncate(5);
Capitalize the people amd company names
// result = "Nelson Nobre"
var result = "nelson nobre".CapitalizeName();
Capitalize the people amd company names
// result1 = "HelloWorld"
var result1 = "Hello World!!!".CleanSpecialCharacters();
// result2 = "Hello-World"
var result2 = "Hello World".CleanSpecialCharacters("-");
Uppercase the first character
// result = "Hello world!!!"
var result = "hello world!!!".UppercaseFirst();
Uppercase the first character
// result = "hello world!!!"
var result = "Hello world!!!".UppercaseFirst();
Convert a text to snake case format
// result = "test_snake_case"
var result = "TestSnakeCase".ToSnakeCase();
Check if the input is an email
// result = true
var result = "nelson@fake.com".IsEmail();
Check if the input is an email
// result = http://localhost:8080/clients/photos
var result = "http://localhost:8080".CombineURL("clients", "photos");
Convert an object to a QueryString.
object parameters = new
{
Name = "Nelson",
Age = 12,
IsValide = true
};
// result = ?Name=Nelson&Age=12&IsValide=True
var result = parameters.ToQueryString();
If you have any questions, comments, or suggestions, please open an issue or create a pull request