Soenneker.Utils.String.LongestCommonSequence
11.0.1045
Prefix Reserved
dotnet add package Soenneker.Utils.String.LongestCommonSequence --version 11.0.1045
NuGet\Install-Package Soenneker.Utils.String.LongestCommonSequence -Version 11.0.1045
<PackageReference Include="Soenneker.Utils.String.LongestCommonSequence" Version="11.0.1045" />
<PackageVersion Include="Soenneker.Utils.String.LongestCommonSequence" Version="11.0.1045" />
<PackageReference Include="Soenneker.Utils.String.LongestCommonSequence" />
paket add Soenneker.Utils.String.LongestCommonSequence --version 11.0.1045
#r "nuget: Soenneker.Utils.String.LongestCommonSequence, 11.0.1045"
#:package Soenneker.Utils.String.LongestCommonSequence@11.0.1045
#addin nuget:?package=Soenneker.Utils.String.LongestCommonSequence&version=11.0.1045
#tool nuget:?package=Soenneker.Utils.String.LongestCommonSequence&version=11.0.1045
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 | net11.0 is compatible. |
-
net11.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 |
|---|---|---|
| 11.0.1045 | 94 | 11/18/2026 |
| 11.0.1044 | 83 | 11/18/2026 |
| 11.0.1043 | 84 | 11/18/2026 |
| 11.0.1041 | 729 | 10/27/2026 |
| 11.0.1040 | 108 | 10/26/2026 |
| 11.0.1039 | 101 | 10/26/2026 |
| 4.0.1038 | 111 | 10/25/2026 |
| 4.0.1037 | 135 | 10/14/2026 |
| 4.0.1036 | 110 | 10/14/2026 |
| 4.0.1030 | 108 | 10/13/2026 |
| 4.0.1028 | 131 | 10/11/2026 |
| 4.0.1027 | 165 | 9/24/2026 |
| 4.0.1026 | 137 | 9/15/2026 |
| 4.0.1025 | 123 | 9/14/2026 |
| 4.0.1024 | 137 | 9/8/2026 |
| 4.0.1023 | 144 | 8/30/2026 |
| 4.0.1022 | 138 | 8/26/2026 |
| 4.0.1021 | 143 | 8/12/2026 |
| 4.0.1020 | 139 | 7/27/2026 |
| 4.0.1019 | 7,243 | 7/16/2026 |
Configure .NET CI defaults and daily source scans