/// <summary> /// Populates the list of filter vars with those that match the VarNames found in the provided list of questions. /// </summary> /// <param name="questions"></param> private void GetFilterVars(List <SurveyQuestion> questions) { string filterVar; int filterVarPos = 0; int filterVarLen; string filterExp; // the filter expression of the variable e.g. [varname]=1, 2, 8 or 9. string[] filterOptionsList; string options; Regex rx; MatchCollection results; while (!FilterText.Equals("")) { FilterVar fv; foreach (SurveyQuestion q in questions) { filterVar = q.VarName.RefVarName; if (!FilterText.Contains(filterVar)) { continue; } rx = new Regex(filterVar + "(=|<|>|<>)" + "(([0-9]+(,\\s[0-9]+)+\\sor\\s[0-9]+)" + "|([0-9]+\\sor\\s[0-9]+)" + "|([0-9]+\\-[0-9]+)" + "|([0-9]+))"); filterVarPos = FilterText.IndexOf(filterVar); filterVarLen = filterVar.Length; results = rx.Matches(FilterText); if (results.Count > 0) { filterExp = results[0].Value; options = filterExp.Substring(filterVarLen + 1); options = Regex.Replace(options, "[^0-9 <->]", ""); filterOptionsList = GetOptionList(options).Split(' '); fv = new FilterVar(); fv.Varname = filterVar; if (filterOptionsList.Length != 0) { fv.ResponseCodes = filterOptionsList.Select(Int32.Parse).ToList(); } // add to the list of filter vars if it is not already there if (!FilterVars.Contains(fv)) { FilterVars.Add(fv); } } else { filterVarPos = 0; continue; } filterVarPos = 0; // trim the filterText to the point after this VarName FilterText = FilterText.Substring(filterVarPos + filterVarLen); } if (filterVarPos == 0) { break; } } }