これが私のシナリオです!
List<String> list = new List<String>();
list.Add("E9215001");
list.Add("E9215045");
list.Add("E1115001");
list.Add("E1115022");
list.Add("E1115003");
list.Add("E2115041");
list.Add("E2115042");
list.Add("E4115021");
list.Add("E5115062");
C# と LINQ を使用して、上記のリストから次の共通部分を抽出する必要があります。
E92150 -> {* E92150 *01, * E92150 *45}から抽出
E11150 -> {* E11150 *01, * E11150 *22, * E11150 *03}から抽出
E21150 -> {* E21150 *41, * E21150 *42}から抽出
E41150 -> {* E41150 *21}から抽出
E51150 -> {* E51150 *62}から抽出
更新: ありがとう! みんな!@mlorbetske と @shelleybutterfly の助けを借りて、私はそれを理解しました!
解決:
list.Select((item, index) => new {
Index=index,
Length=Enumerable.Range(1, (item.Length-2)) //I'm ignoring the last 2 characters
.Reverse()
.First(proposedLength => list.Count(innerItem =>
innerItem.StartsWith(item.Substring(0, proposedLength))) >
1)}).Select(n => list[n.Index].Substring(0, n.Length)).Distinct()