Hto3.StringHelpers 1.1.9

dotnet add package Hto3.StringHelpers --version 1.1.9                
NuGet\Install-Package Hto3.StringHelpers -Version 1.1.9                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hto3.StringHelpers" Version="1.1.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hto3.StringHelpers --version 1.1.9                
#r "nuget: Hto3.StringHelpers, 1.1.9"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hto3.StringHelpers as a Cake Addin
#addin nuget:?package=Hto3.StringHelpers&version=1.1.9

// Install Hto3.StringHelpers as a Cake Tool
#tool nuget:?package=Hto3.StringHelpers&version=1.1.9                

logo

Hto3.StringHelpers

License Hto3.StringHelpers Downloads Build Status codecov Codacy Badge

Features

A set of extension methods that can be used to manipulate strings solving common dev problems.

RemoveCharactersAtBegining

Remove a specified amout of characters at the begining of string.

"Apple".RemoveCharactersAtBegining(1) == "pple";

RemoveCharactersAtEnd

Remove a specified amout of characters at the end of string.

"Apple".RemoveCharactersAtEnd(1) == "Appl";

RemoveSpaces

Remove all spaces ' '.

"Five steps to complish".RemoveSpaces() == "Fivestepstocomplish";

RemoveLineBreaks

Remove all line breaks.

"Line\r\nbreaks\r\nare\r\ngreat!".RemoveLineBreaks() == "Linebreaksaregreat!";

PrependMissing

If the text does not start with a especified text, then this specified text will be added to the string.

@":\Program Files (x86)\Java".PrependMissing("C") == @"C:\Program Files (x86)\Java";

AppendMissing

If the text does not end with a especified text, then this specified text will be added to the string.

@"C:\Program Files (x86)\Java".AppendMissing("\\") == @"C:\Program Files (x86)\Java\";

NullIf

If the text is equal to a specified value, then return null.

"0".NullIf("0") == null;

Coalesce

Return the first non-null value.

Helpers.Coalesce(null, null, "123", "abc") == "123";

RandomString

Generate a ramdom string containing letters and numbers.

Helpers.RandomString(8) == "a84583fc";

IsAlphanumeric

Verify if a text is alpha numeric.

"azAZ09".IsAlphanumeric() == true;

ToAlphanumeric

Converts the specified text to an alpha-numeric string by removing all non-alpha-numeric characters.

"[a-z|A-Z|0-9]".ToAlphanumeric() == "azAZ09";

ToCsvSafe

Makes a string safe to 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 others caracters from a text lefting only numbers.

"df89e#dKf".NumbersOnly() == "89";

LettersOnly

Strip all others caracters from a text lefting only letters.

"df89é#dKf".LettersOnly() == "dfédKf";

ExceptNumbers

Strip all others caracters from a text lefting only non-numbers.

"59385gg#451".ExceptNumbers() == "gg#";

Extract some characters from right to left.

"Apple".Right(3) == "ple";

Left

Extract some characters from left to right.

"Apple".Left(3) == "App";

Reverse

Reverse the characters sequence.

"Apple".Reverse() == "elppA";

ReplaceIgnoringCase

Replace a text with another one ignoring case.

"The ReCiPe of madness".ReplaceIgnoringCase("recipe", "master") == "The master of madness";

ReplaceWholeWord

Replace 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 are replaced with another specified string.

"Car car car car".ReplaceFirstOccurrence("car", "bus") == "Car bus car car";

TryGetFirstName

Tries to get the first name of a full name.

String test = null;
Assert.AreEqual("John Doe".TryGetFirstName(out test), true);
Assert.AreEqual(test, "John");

TryGetLastName

Tries to get the last name of 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.

"11111111".FormatCEP() == "11111-111";

IsNumber

Verify if a text is 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 character.

"jäspion-".ReplaceNonASCIICharactersWith('?') == "j?spion-";

ReplaceNonANSICharactersWith

Replace all non-ANSI characters with a character.

"jäspion-ﮝ".ReplaceNonANSICharactersWith('?') == "jäspion-?";

RemoveAccents

Remove accents replacing the character with the equivalent without accent.

"jäspion".RemoveAccents() == "jaspion";

TrySubstring

Try to execute substring over a string. Returns false if the operation is impossible, else true.

String resultString = null;
bool success = "abc".TrySubstring(2, out resultString);

CenterAlignText

Center a text inside a fixed length using space characters ' '.

"job".CenterAlignText(30) == "             job            ";

MaskText

Mask text with a replacement char.

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);

//result 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 chars:

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 the application is running on Windows, all '/' will be replaced by '\', else all '\' will be replaced by '/'.

//on Windows
"/var/lib/file.txt".NormalizePathSlashes() == "\\var\\lib\\file.txt";

TrimExtraSpaces

Remove extra space between words.

"abc     abc".TrimExtraSpaces() == "abc abc";

CalcBase64SizeBytes

Calculate the content size of a base64 string. Return size in Bytes.

"AA==".CalcBase64SizeBytes() == 1;

ContainsAnyOfTheseWords

Check if 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 if 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 Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.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.1.9 203 1/7/2024
1.1.8 131 1/5/2024
1.1.7 162 5/19/2023
1.1.6 166 5/18/2023
1.1.5 371 11/21/2022
1.1.4 331 11/19/2022
1.1.3 483 5/1/2022
1.1.2 438 3/27/2022
1.1.1 374 11/15/2021
1.0.10 438 7/9/2021
1.0.9 360 2/17/2021
1.0.8 499 7/8/2020
1.0.7 507 1/21/2020
1.0.6 555 9/28/2019
1.0.5 529 7/21/2019
1.0.4 553 6/19/2019
1.0.3 721 12/23/2018
1.0.2 722 11/20/2018
1.0.1 728 11/10/2018
1.0.0 713 11/6/2018