StringSimilarity 1.0.3

dotnet add package StringSimilarity --version 1.0.3
                    
NuGet\Install-Package StringSimilarity -Version 1.0.3
                    
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="StringSimilarity" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StringSimilarity" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="StringSimilarity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StringSimilarity --version 1.0.3
                    
#r "nuget: StringSimilarity, 1.0.3"
                    
#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.
#:package StringSimilarity@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StringSimilarity&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=StringSimilarity&version=1.0.3
                    
Install as a Cake Tool

StringSimilarity

This class library calculates a score from 0 to 1 based on the similarity of two supplied strings.

StringSimilarity targets .NET Standard 2.1, .NET Core 3.1, .NET Framework 4.5.2, .NET 5.0, and .NET 6.0.

Help or Feedback

First things first - do you need help or have feedback? Contact me at joel dot christner at gmail dot com or file an issue here!

New in v1.0.2.2

  • Maintenance release; library behavior is unchanged
  • Symbol package (.snupkg) now published alongside the NuGet package
  • Test dependencies refreshed (Touchstone 0.2.0, xUnit runner 4.0.0, NUnit 5.0.0, Microsoft.NET.Test.Sdk 18.10.1, coverlet 10.1.0)

Score Computation

  • If one string is null/empty and the other is not, the score is 0
  • If both strings are null/empty, the score is 1
  • If both strings are equal, the score is 1
  • Otherwise, a length score is multiplied by a character match score, where length score = (min / max) and character match score is (num matching / total)
    • The character match score compares the sets of distinct characters in each string; total is the number of distinct characters in whichever string has more
    • Comparison is case-sensitive and ordinal, so ABC versus abc scores 0
    • Character order and frequency are not considered, so anagrams of the same length (for example listen and silent) score 1

Example

Refer to the Test project for an interactive example.

using Similarity;

Console.Write("String 1 : ");
string str1 = Console.ReadLine(); 
Console.Write("String 2 : ");
string str2 = Console.ReadLine();
Console.WriteLine("Score    : " + StringSimilarity.Calculate(str1, str2));

Running the Tests

Automated tests are built with Touchstone. All test cases live in Test.Shared and are executed by three runners:

  • Test.Automated - console runner (dotnet run --project Test.Automated -f net8.0, add -- --results results.json to export JSON)
  • Test.Xunit - xUnit runner (dotnet test Test.Xunit)
  • Test.Nunit - NUnit runner (dotnet test Test.Nunit)

The Test project is an interactive console application for trying the library by hand.

Version History

Refer to CHANGELOG.md for the full version history.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  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.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.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.0.3 53 11/18/2026
1.0.2.2 171 10/3/2026
1.0.2.1 163,328 11/12/2021
1.0.2 20,663 11/15/2020
1.0.1 3,500 3/13/2019
1.0.0 1,717 11/9/2017

Maintenance release: refreshed test dependencies, symbol package (snupkg) published