Soenneker.Utils.String.LongestCommonSequence
4.0.1024
Prefix Reserved
dotnet add package Soenneker.Utils.String.LongestCommonSequence --version 4.0.1024
NuGet\Install-Package Soenneker.Utils.String.LongestCommonSequence -Version 4.0.1024
<PackageReference Include="Soenneker.Utils.String.LongestCommonSequence" Version="4.0.1024" />
<PackageVersion Include="Soenneker.Utils.String.LongestCommonSequence" Version="4.0.1024" />
<PackageReference Include="Soenneker.Utils.String.LongestCommonSequence" />
paket add Soenneker.Utils.String.LongestCommonSequence --version 4.0.1024
#r "nuget: Soenneker.Utils.String.LongestCommonSequence, 4.0.1024"
#:package Soenneker.Utils.String.LongestCommonSequence@4.0.1024
#addin nuget:?package=Soenneker.Utils.String.LongestCommonSequence&version=4.0.1024
#tool nuget:?package=Soenneker.Utils.String.LongestCommonSequence&version=4.0.1024
Soenneker.Utils.String.LongestCommonSequence
Longest common subsequence scoring for strings, with normalized and percentage results.
Installation
dotnet add package Soenneker.Utils.String.LongestCommonSequence
Usage
using Soenneker.Utils.String.LongestCommonSequence;
var text1 = "This is a test";
var text2 = "This is another test";
double score = LcsStringUtil.CalculateSimilarity(text1, text2);
double percentage = LcsStringUtil.CalculateSimilarityPercentage(text1, text2);
// score == 0.7
// percentage == 70
The longest common subsequence preserves character order but does not require matching characters to be adjacent. The normalized score is:
LCS length / length of the longer input
CalculateSimilarity returns a value from 0 to 1; CalculateSimilarityPercentage multiplies it by 100. Identical strings, including two empty strings, return 1 (or 100%).
Comparison rules and cost
- Comparison is case-sensitive.
- The algorithm compares UTF-16 code units, not words, Unicode scalar values, or grapheme clusters.
- Whitespace and punctuation participate like any other character.
- Runtime is
O(m × n)for input lengthsmandn. CalculateSimilarityusesO(min(m, n))working memory.
For long inputs, the quadratic runtime can be significant. Normalize casing or Unicode representation before calling when your application requires those equivalences.
Prefix lengths
CalculateSimilarityArray(first, second) exposes the final dynamic-programming row. Element j contains the LCS length between first and the first j characters of second; the returned array therefore has second.Length + 1 elements. Use its last element for the complete LCS length.
All methods require non-null strings.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
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 |
|---|---|---|
| 4.0.1024 | 40 | 9/8/2026 |
| 4.0.1023 | 94 | 8/30/2026 |
| 4.0.1022 | 95 | 8/26/2026 |
| 4.0.1021 | 105 | 8/12/2026 |
| 4.0.1020 | 110 | 7/27/2026 |
| 4.0.1019 | 261 | 7/16/2026 |
| 4.0.1018 | 109 | 7/14/2026 |
| 4.0.1017 | 164 | 6/18/2026 |
| 4.0.1016 | 160 | 6/9/2026 |
| 4.0.1014 | 132 | 5/12/2026 |
| 4.0.1013 | 123 | 4/23/2026 |
| 4.0.1012 | 120 | 4/21/2026 |
| 4.0.1011 | 132 | 4/14/2026 |
| 4.0.1010 | 137 | 3/12/2026 |
| 4.0.1005 | 135 | 3/10/2026 |
| 4.0.1004 | 125 | 3/10/2026 |
| 4.0.1003 | 126 | 3/9/2026 |
| 4.0.1002 | 123 | 3/9/2026 |
| 4.0.1001 | 115 | 3/4/2026 |
| 4.0.1000 | 136 | 2/10/2026 |
Update dependency Microsoft.Extensions.DependencyInjection.Abstractions to 10.0.12 (#1587)