FolkerKinzel.Strings 1.2.0

.NET library, containing extension methods for System.String, System.Text.StringBuilder and System.ReadOnlySpan<Char>.

Install-Package FolkerKinzel.Strings -Version 1.2.0
dotnet add package FolkerKinzel.Strings --version 1.2.0
<PackageReference Include="FolkerKinzel.Strings" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FolkerKinzel.Strings --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FolkerKinzel.Strings, 1.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install FolkerKinzel.Strings as a Cake Addin
#addin nuget:?package=FolkerKinzel.Strings&version=1.2.0

// Install FolkerKinzel.Strings as a Cake Tool
#tool nuget:?package=FolkerKinzel.Strings&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

FolkerKinzel.Strings

.NET library, containing extension methods for String, StringBuilder and ReadOnlySpan<Char>.

Content:

  • Extension methods which return an equal (and therefore persistable) Int32 hashcode for an identical Char sequence everytime they are called - even on String, StringBuilder or ReadOnlySpan<Char>. The hashcodes can be specified to hash the sequence ordinal, ordinal case insensitive or alphanumeric case insensitive. The hashcodes produced by this library are not equivalent to the hashcodes produced by the .NET-Framework 4.0 System.String class, because they use roundshifting to keep more information. Don't use these hashcodes for security critical purposes (such as hashing passwords)!

  • Download Reference (English)

  • Projektdokumentation (Deutsch) herunterladen

IMPORTANT: On some systems, the content of the CHM file is blocked. Before opening the file, right click on it, select Properties, and check the "Allow" checkbox - if it is present - in the lower right corner of the General tab in the Properties dialog.

Example:

using System;
using System.Text;
using FolkerKinzel.Strings;

namespace Examples
{
  public static class ShortExample
  {
    public static void CreateConstantStringHashes()
    {
       Console.WriteLine("Ordinal:");
       const string s1 = "Hello Folker!";
       Console.WriteLine(
         $"{s1.GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine(
         $"{new StringBuilder().Append(s1).GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine("OrdinalIgnoreCase:");
       Console.WriteLine(
         $"{"HELLO FOLKER!".GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine(
         $"{"Hello Folker!".AsSpan().GetStableHashCode(HashType.OrdinalIgnoreCase),10:X08}");
       Console.WriteLine("AlphaNumericIgnoreCase:");
       Console.WriteLine(
         $"{"HELLO FOLKER!".AsSpan().GetStableHashCode(HashType.AlphaNumericIgnoreCase),10:X08}");
       Console.WriteLine(
         $"{new StringBuilder().Append("&: !heL##Lof OLker *").GetStableHashCode(HashType.AlphaNumericIgnoreCase),10:X08}");

       // Different HashTypes may produce different hashcodes on the same Char sequence
       // and must therefore not be mixed:
       Console.WriteLine("Same String - different HashTypes:");
       Console.WriteLine(
          $"{s1.GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine(
         $"{s1.GetStableHashCode(HashType.OrdinalIgnoreCase),10:X08}");
       Console.WriteLine(
         $"{s1.GetStableHashCode(HashType.AlphaNumericIgnoreCase),10:X08}");
   }
 }
}
/*
Output:

Ordinal:
  A31FA6EC
  A31FA6EC
OrdinalIgnoreCase:
  1BBFB34C
  1BBFB34C
AlphaNumericIgnoreCase:
  C672C38C
  C672C38C
Same String - different HashTypes:
  A31FA6EC
  1BBFB34C
  C672C38C
*/

FolkerKinzel.Strings

.NET library, containing extension methods for String, StringBuilder and ReadOnlySpan<Char>.

Content:

  • Extension methods which return an equal (and therefore persistable) Int32 hashcode for an identical Char sequence everytime they are called - even on String, StringBuilder or ReadOnlySpan<Char>. The hashcodes can be specified to hash the sequence ordinal, ordinal case insensitive or alphanumeric case insensitive. The hashcodes produced by this library are not equivalent to the hashcodes produced by the .NET-Framework 4.0 System.String class, because they use roundshifting to keep more information. Don't use these hashcodes for security critical purposes (such as hashing passwords)!

  • Download Reference (English)

  • Projektdokumentation (Deutsch) herunterladen

IMPORTANT: On some systems, the content of the CHM file is blocked. Before opening the file, right click on it, select Properties, and check the "Allow" checkbox - if it is present - in the lower right corner of the General tab in the Properties dialog.

Example:

using System;
using System.Text;
using FolkerKinzel.Strings;

namespace Examples
{
  public static class ShortExample
  {
    public static void CreateConstantStringHashes()
    {
       Console.WriteLine("Ordinal:");
       const string s1 = "Hello Folker!";
       Console.WriteLine(
         $"{s1.GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine(
         $"{new StringBuilder().Append(s1).GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine("OrdinalIgnoreCase:");
       Console.WriteLine(
         $"{"HELLO FOLKER!".GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine(
         $"{"Hello Folker!".AsSpan().GetStableHashCode(HashType.OrdinalIgnoreCase),10:X08}");
       Console.WriteLine("AlphaNumericIgnoreCase:");
       Console.WriteLine(
         $"{"HELLO FOLKER!".AsSpan().GetStableHashCode(HashType.AlphaNumericIgnoreCase),10:X08}");
       Console.WriteLine(
         $"{new StringBuilder().Append("&: !heL##Lof OLker *").GetStableHashCode(HashType.AlphaNumericIgnoreCase),10:X08}");

       // Different HashTypes may produce different hashcodes on the same Char sequence
       // and must therefore not be mixed:
       Console.WriteLine("Same String - different HashTypes:");
       Console.WriteLine(
          $"{s1.GetStableHashCode(HashType.Ordinal),10:X08}");
       Console.WriteLine(
         $"{s1.GetStableHashCode(HashType.OrdinalIgnoreCase),10:X08}");
       Console.WriteLine(
         $"{s1.GetStableHashCode(HashType.AlphaNumericIgnoreCase),10:X08}");
   }
 }
}
/*
Output:

Ordinal:
  A31FA6EC
  A31FA6EC
OrdinalIgnoreCase:
  1BBFB34C
  1BBFB34C
AlphaNumericIgnoreCase:
  C672C38C
  C672C38C
Same String - different HashTypes:
  A31FA6EC
  1BBFB34C
  C672C38C
*/

Release Notes

Adds support for Netstandard 2.0 and .NET-Framework 4.5.
     
     The extension method GetStableHashCode is now available also on ReadOnlySpan<char> on all supported platforms except .NET Framework 4.0.

     The enum value HashType.AlphaNumericNoCase is now marked as obsolete and has a replacement in HashType.AlphaNumericIgnoreCase.

  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

  • .NETStandard 2.0

  • .NETStandard 2.1

    • 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 History

Version Downloads Last updated
1.2.0 42 2/13/2021
1.1.0 247 7/5/2020