I have a sql string as follows:
select a, b, c from test where a = s and b = 3
Using C# 2.0 specifically, how can I get:
a = s, b = 3
But in the form of a collection, so one member is “a = s”, the other is “b = 3”?
Thanks
P.S. Table names have been changed but the point remains
EDIT: I have just realised I could get a substring from where onwards and then split it where there are commas and an and. Is there a better way?
Are you asking how to take part of the sql query string, splitting it and storing it in a collection?
Use the built-in string functions or built a regular expression to extract them. A naive approach would be to split the sql string after ‘where’ and then again at each comma.
This only handles splitting the where conditions that are seperated by a comma. If more conditions such as “And” or “Or” should be supported then add them to the array of the second split call:
What is the purpose of isolating each of these conditions?