Hto3.StringHelpers
1.2.0
dotnet add package Hto3.StringHelpers --version 1.2.0
NuGet\Install-Package Hto3.StringHelpers -Version 1.2.0
<PackageReference Include="Hto3.StringHelpers" Version="1.2.0" />
<PackageVersion Include="Hto3.StringHelpers" Version="1.2.0" />
<PackageReference Include="Hto3.StringHelpers" />
paket add Hto3.StringHelpers --version 1.2.0
#r "nuget: Hto3.StringHelpers, 1.2.0"
#:package Hto3.StringHelpers@1.2.0
#addin nuget:?package=Hto3.StringHelpers&version=1.2.0
#tool nuget:?package=Hto3.StringHelpers&version=1.2.0

Hto3.StringHelpers
Features
A set of extension methods that can be used to manipulate strings and solve common development problems.
RemoveCharactersAtBegining
Remove a specified amount of characters from the beginning of a string.
"Apple".RemoveCharactersAtBegining(1) == "pple";
RemoveCharactersAtEnd
Remove a specified amount of characters from the end of a string.
"Apple".RemoveCharactersAtEnd(1) == "Appl";
RemoveSpaces
Remove all space characters (' ').
"Five steps to accomplish".RemoveSpaces() == "Fivestepstoaccomplish";
RemoveLineBreaks
Remove all line breaks.
"Line\r\nbreaks\r\nare\r\ngreat!".RemoveLineBreaks() == "Linebreaksaregreat!";
PrependMissing
If the text does not start with the specified value, that value will be added to the start of the string.
@":\Program Files (x86)\Java".PrependMissing("C") == @"C:\Program Files (x86)\Java";
AppendMissing
If the text does not end with the specified value, that value will be added to the end of the string.
@"C:\Program Files (x86)\Java".AppendMissing("\\") == @"C:\Program Files (x86)\Java\";
NullIf
If the text is equal to a specified value, returns null.
"0".NullIf("0") == null;
Coalesce
Returns the first non-null value.
Helpers.Coalesce(null, null, "123", "abc") == "123";
RandomString
Generate a random string containing letters and numbers.
Helpers.RandomString(8) == "a84583fc";
IsAlphanumeric
Verify whether a text is alphanumeric.
"azAZ09".IsAlphanumeric() == true;
ToAlphanumeric
Converts the specified text to an alphanumeric string by removing all non-alphanumeric characters.
"[a-z|A-Z|0-9]".ToAlphanumeric() == "azAZ09";
ToCsvSafe
Makes a string safe to be used in a CSV file by including double quotes when needed.
" Cave rats,\r\ngiant cats!".ToCsvSafe() == "\" Cave rats,\r\ngiant cats!\"";
NumbersOnly
Strip all other characters from a text, leaving only numbers.
"df89e#dKf".NumbersOnly() == "89";
LettersOnly
Strip all other characters from a text, leaving only letters.
"df89é#dKf".LettersOnly() == "dfédKf";
ExceptNumbers
Strip all other characters from a text, leaving only non-numeric characters.
"59385gg#451".ExceptNumbers() == "gg#";
Right
Extract characters from the right.
"Apple".Right(3) == "ple";
Left
Extract characters from the left.
"Apple".Left(3) == "App";
Reverse
Reverse the character sequence.
"Apple".Reverse() == "elppA";
ReplaceIgnoringCase
Replace text with another value, ignoring case.
"The ReCiPe of madness".ReplaceIgnoringCase("recipe", "master") == "The master of madness";
ReplaceWholeWord
Replace a whole word.
"So far so good".ReplaceWholeWord("far", "long") == "So long so good";
ReplaceFirstOccurrence
Returns a new string in which only the first occurrence of a specified string in the current instance is replaced with another specified string.
"Car car car car".ReplaceFirstOccurrence("car", "bus") == "Car bus car car";
TryGetFirstName
Try to get the first name from a full name.
String test = null;
Assert.AreEqual("John Doe".TryGetFirstName(out test), true);
Assert.AreEqual(test, "John");
TryGetLastName
Try to get the last name from a full name.
String test = null;
Assert.AreEqual("John Doe".TryGetLastName(out test), true);
Assert.AreEqual(test, "Doe");
FormatCPF
Format a Brazilian CPF.
"11111111111".FormatCPF() == "111.111.111-11";
FormatCNPJ
Format a Brazilian CNPJ.
"11111111111111".FormatCNPJ() == "11.111.111/1111-11";
FormatCEP
Format a Brazilian ZIP code (CEP).
"11111111".FormatCEP() == "11111-111";
IsNumber
Verify whether a text represents a number.
"1111".IsNumber() == true;
RemoveNonASCIICharacters
Remove all non-ASCII characters from a text.
"jäspion-".RemoveNonASCIICharacters() == "jspion-";
RemoveNonANSICharacters
Remove all non-ANSI characters from a text.
"jäspion-ﮝ".RemoveNonANSICharacters() == "jäspion-";
ReplaceNonASCIICharactersWith
Replace all non-ASCII characters with a specified character.
"jäspion-".ReplaceNonASCIICharactersWith('?') == "j?spion-";
ReplaceNonANSICharactersWith
Replace all non-ANSI characters with a specified character.
"jäspion-ﮝ".ReplaceNonANSICharactersWith('?') == "jäspion-?";
RemoveAccents
Remove accents by replacing characters with their unaccented equivalents.
"jäspion".RemoveAccents() == "jaspion";
TrySubstring
Attempt to perform a substring operation on a string. Returns false if the operation is invalid; otherwise, returns true.
String resultString = null;
bool success = "abc".TrySubstring(2, out resultString);
CenterAlignText
Center-align text inside a fixed length using space characters.
"job".CenterAlignText(30) == " job ";
MaskText
Mask text using a replacement character.
var text = "The cat is a good friend too.";
var coverage = 0.5f; // 50%
var mode = MaskTextMode.Begining;
// Possible modes:
// var mode = MaskTextMode.Ending;
// var mode = MaskTextMode.Center;
// var mode = MaskTextMode.Intervaled;
// var mode = MaskTextMode.Ends;
// var mode = MaskTextMode.Random;
var result = StringHelpers.MaskText(text, coverage, mode);
// Examples by mode:
result == "*** *** ** * ***d friend too."; // Begining
// result == "The cat is a go** ****** ****"; // Ending
// result == "The cat ** * **** *****d too."; // Center
// result == "**e *a* i* a *o*d *r*e*d *o*."; // Intervaled
// result == "*** *** is a good frie** ****"; // Ends
// result == "Th* c** i* a *oo* **i*n* t**."; // Random
Do not mask some characters:
var text = "111.111.111-00";
var coverage = 0.7f; // 70%
var mode = MaskTextMode.Intervaled;
var replacementChar = '°';
var skip = new[] { '.', '-' };
// Act
var result = StringHelpers.MaskText(text, coverage, mode, replacementChar, skip);
result == "°°1.°°°.1°°-°0";
NormalizePathSlashes
Normalize the slashes in a path. If running on Windows, all '/' will be replaced by ''; otherwise all '' will be replaced by '/'.
// on Windows
"/var/lib/file.txt".NormalizePathSlashes() == "\\var\\lib\\file.txt";
TrimExtraSpaces
Remove extra spaces between words.
"abc abc".TrimExtraSpaces() == "abc abc";
CalcBase64SizeBytes
Calculate the content size of a base64 string and return the size in bytes.
"AA==".CalcBase64SizeBytes() == 1;
ContainsAnyOfTheseWords
Check whether the text contains any of the provided words.
var text = @"Historically, the world of data and the world of objects " +
@"have not been well integrated. Programmers work in C# or Visual Basic " +
@"and also in SQL or XQuery. On the one side are concepts such as classes, " +
@"objects, fields, inheritance, and .NET APIs. On the other side " +
@"are tables, columns, rows, nodes, and separate languages for dealing with " +
@"them. Data types often require translation between the two worlds; there are " +
@"different standard functions. Because the object world has no notion of query, a " +
@"query can only be represented as a string without compile-time type checking or " +
@"IntelliSense support in the IDE. Transferring data from SQL tables or XML trees to " +
@"objects in memory is often tedious and error-prone.";
var words = new[] { "memory", "jeopardize" };
// The word "memory" is in the text
text.ContainsAnyOfTheseWords(words) == true;
ContainsAllOfTheseWords
Check whether the text contains all of the provided words.
var text = @"Historically, the world of data and the world of objects " +
@"have not been well integrated. Programmers work in C# or Visual Basic " +
@"and also in SQL or XQuery. On the one side are concepts such as classes, " +
@"objects, fields, inheritance, and .NET APIs. On the other side " +
@"are tables, columns, rows, nodes, and separate languages for dealing with " +
@"them. Data types often require translation between the two worlds; there are " +
@"different standard functions. Because the object world has no notion of query, a " +
@"query can only be represented as a string without compile-time type checking or " +
@"IntelliSense support in the IDE. Transferring data from SQL tables or XML trees to " +
@"objects in memory is often tedious and error-prone.";
var words = new[] { "object", "without" };
// The words "object" and "without" are in the text
text.ContainsAllOfTheseWords(words) == true;
| 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 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.0 | 0 | 3/15/2026 |
| 1.1.9 | 351 | 1/7/2024 |
| 1.1.8 | 208 | 1/5/2024 |
| 1.1.7 | 322 | 5/19/2023 |
| 1.1.6 | 310 | 5/18/2023 |
| 1.1.5 | 511 | 11/21/2022 |
| 1.1.4 | 489 | 11/19/2022 |
| 1.1.3 | 655 | 5/1/2022 |
| 1.1.2 | 604 | 3/27/2022 |
| 1.1.1 | 571 | 11/15/2021 |
| 1.0.10 | 618 | 7/9/2021 |
| 1.0.9 | 569 | 2/17/2021 |
| 1.0.8 | 685 | 7/8/2020 |
| 1.0.7 | 731 | 1/21/2020 |
| 1.0.6 | 784 | 9/28/2019 |
| 1.0.5 | 749 | 7/21/2019 |
| 1.0.4 | 757 | 6/19/2019 |
| 1.0.3 | 943 | 12/23/2018 |
| 1.0.2 | 955 | 11/20/2018 |
| 1.0.1 | 964 | 11/10/2018 |