我一直在研究这个问题一段时间,我希望我能得到一些解决方案。
我有一个句子,其中包含我想提取的关键信息。
提取这些字符串后,我会将它们保存为一个数组,然后将这些字符串与我的数据库中存在的字符串进行比较。
我遇到的问题是成功提取字符串。
例如,我有这句话:
These are a list of automobiles along with their production dates: AC 3000ME (1979-1984), AC Shelby-Cobra (1961-2004), AC Frua (1965-1973).
我想提取:3000ME、、Shelby-Cobra和Frua。
下面是代码:
public string CarModelMethod()
{
string sentence = "These are a list of automobiles along with their production dates: AC 3000ME (1979-1984), AC Shelby-Cobra (1961-2004), AC Frua (1965-1973)";
string[] array = sentence.Split(',');
CarModel carModel = new CarModel();
foreach(var item in array)
{
var carDataSource = _context.CarTable.Where(x => EF.Functions.Like(x.CarModelName, $"%{item}%")).Select(x => x.CarId);
foreach(var id in carDataSource)
{
carModel.CarId = id;
_context.CarModel.Add(carModel);
_context.SaveChanges();
}
}
return null;
}
