Re: [問題] 字串比對

作者: bantime (景)   2015-11-22 02:26:06
不知道有沒有誤解你的意思
string[] addressDatas = new string[0];
string pUserInput = "";
string[] keyWords = pUserInput.Split (' ', ',');
var result = from tar in addressDatas
where keyWords.Count (r => tar.Contains (r)) > 1//符合的數量
select tar;
或者進階一點
string[] addressDatas = new string[0];
string pUserInput = "";
string[] keyWords = pUserInput.Split (' ', ',');
var result = from tar in addressDatas
let num = keyWords.Count (r => tar.Contains (r))
where num > 0
let anonymous = new {nNum = num,address = tar}
orderby anonymous.nNum descending
select anonymous;

Links booklink

Contact Us: admin [ a t ] ucptt.com