-3

I have a field which is that consists from delimiter (dynamic number) parts:

(c44 EE0),(c2 EE7),(e79 EE10),(c2 EE90)

my field is a comma delimiter field and how can i split it (in Linq) and search in the parts separately?

i.e. query : get those parts which have C2

please let me describe my problem again i have a field in sql server which i want to get result of that via LINQ ,

above field named code in SNP table as you can see this code field is tab delimited so i would like to catch those records which have C2 in their at least one part. Its simple to split a field via 'comma delimiter' but how can i do this in a linq query?

user3616494
  • 63
  • 10

1 Answers1

2
var field = "(c44 EE0),(c2 EE7),(e79 EE10),(c2 EE90)";
var result = field.Split(',').Where(x => x.Contains("c2"));
rob
  • 8,134
  • 8
  • 58
  • 68
  • how can get query like this if have multiple target text like : `var query = (from c in db.SNPs where c.Effect.Split(',').Where(x =>.Contains("c2") || x.Contains("c4")) select c);` – user3616494 Jul 10 '14 at 12:30
  • have a look at Intersect http://stackoverflow.com/questions/11285045/intersect-two-lists-with-different-objects Might be a good idea to create a new question. – rob Jul 10 '14 at 12:45
  • for this code `var query = (from c in db.SNPs where c.Effect.Split(',').Any(x => x.Contains("C2")) select c).ToArray();` i faced with this error **The argument 'value' was the wrong type. Expected 'System.String'. Actual 'System.String[]'.** how can i handle string Array?? – user3616494 Jul 10 '14 at 13:45
  • @user3616494 what exactly do you need to come out of the query? by your example you are selecting the whole object(in this case SNPs objects). – terrybozzio Jul 10 '14 at 16:00
  • please let me describe my problem again i have a field in sql server which i want to get result of that via LINQ , above field named code in SNP table as you can see this code field is tab delimited so i would like to catch those records which have C2 in their at least one part. Its simple to split a field via 'comma delimiter' but how can i do this in a linq query? – user3616494 Jul 20 '14 at 15:32