0
我有一個計數。我有數據庫中的數據。我想根據輸入的動詞找到第一個匹配的單詞。找到兩個句子之間匹配的第一個單詞
public class HesapPlanı
{
public string hesapKodu { get; set; }
public string hesapAdi { get; set; }
}
查詢
//Actually they come from the database.
List<HesapPlanı> hesap = new List<HesapPlanı>();
hesap.Add(new HesapPlanı { hesapKodu = "100 01 001", hesapAdi = "Kasa" });
hesap.Add(new HesapPlanı { hesapKodu = "120 01 001", hesapAdi = "CARİ KART" });
hesap.Add(new HesapPlanı { hesapKodu = "340 01 001", hesapAdi = "AFYON ÖDEMESİ" });
hesap.Add(new HesapPlanı { hesapKodu = "350 01 001", hesapAdi = "Kasa" });
hesap.Add(new HesapPlanı { hesapKodu = "360 02 001", hesapAdi = "STOPAJ ÖDEMESİ" });
string kalan = null;
string[] liste1 = "GELEN EFT - CARİ ÖDEMESİ".Split(new char[] { ' ', '-' });
string[] liste2 = null;
string sorgu = null;
foreach (var item in hesap.Select(h => h.hesapAdi))
{
liste2 = item.Split(new char[] { ' ', '-' });
var kume = liste1.Intersect(liste2);
sorgu = liste2.Intersect(kume).FirstOrDefault();
if (!string.IsNullOrWhiteSpace(sorgu))
{
kalan = sorgu;
}
}
Console.WriteLine(hesap.Where(m => m.hesapAdi.Contains(kalan)).FirstOrDefault().hesapKodu);
這些操作的結果是: 「340 01 001」
實際應該是這個結果: 「120 01 001」
結果列表。我想得到一個結果:「340 01 001」。結果:「CARİ」返回。 –