本文介绍了如何使用LINQ基于逗号分隔值获取行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, Sno     User_ID ---      ----------- 1       S191,S192,S193,S195 2       S291,S192,S193,SSS 3       S291,S292,S393,S395 我的列col1中有逗号分隔的数据,我有一个单字符串usong LINQ 我的输入是 String str_user_id = S193 必需输出是:我希望那个匹配任何User_id的行进入User_ID列 喜欢 1    S191,S192,S193,S195 2    S291,S192,S193,SSS 这个 提前感谢 我尝试过: 我试过这个,没有得到正确的输出 string prefixMatch = SearchDistCode +,; string suffixMatch =,+ SearchDistCode; string innerMatch =,+ SearchDistCode +, ; var dist_code =(来自r in en.temp_rate_target_schemes_new where(r.Distributor_Code.StartsWith(prefixMatch)|| r。 Distributor_Code.Contains(innerMatch)|| r.Distributor_Code.EndsWith(suffixMatch)||(!r.Distributor_Code.Contains(,)&& r.Distributor_Code == SearchDistCode)) 选择新的 { ratebrokcode = r.Rate_Structure_ID }。ToList(); 解决方案 参考这篇文章如何查询逗号分隔值列在SQL中 [ ^ ] Hi all,Sno    User_ID---    -----------1       S191,S192,S193,S1952       S291,S192,S193,SSS3       S291,S292,S393,S395I have comma-separated data in my column called col1, and I have an Single String usong LINQmy input is String str_user_id=S193Required Output is : I want that row which is match any User_id into User_ID Columnlike1    S191,S192,S193,S1952    S291,S192,S193,SSSthisthanks in advanceWhat I have tried:I have tried this, not getting the correct outputstring prefixMatch = SearchDistCode + ","; string suffixMatch = "," + SearchDistCode; string innerMatch = "," + SearchDistCode + ","; var dist_code = (from r in en.temp_rate_target_schemes_new where (r.Distributor_Code.StartsWith(prefixMatch) || r.Distributor_Code.Contains(innerMatch) || r.Distributor_Code.EndsWith(suffixMatch) || (!r.Distributor_Code.Contains(",") && r.Distributor_Code == SearchDistCode)) select new { ratebrokcode = r.Rate_Structure_ID }).ToList(); 解决方案 这篇关于如何使用LINQ基于逗号分隔值获取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-26 00:11