I have a string in this particular format
string LogInIDs = 124,345, 876 | 765,322, 98 | 565,99
All the numbers in the string are Unique LogIn ID. Using the Pipe symbol, the grouping is done of id's. Now, Suppose the LogInID is 345, then i need to bind other numbers (in this case 124 & 876) which are in the group in a dropdown. The below function is what i have made to retrieve the other numbers.
Can anybody come up with any better idea or suggestion
public static List<string> RetrieveAffCodes(string LogInIDs , string LogInID)
{
List<string> _finale = new List<string>();
string[] sep1 = new string[1];
sep1[0] = "|";
int count = LogInIDs.Count(x => x == '|');
string[] groups = new string[count + 1];
groups = LogInIDs.Split(sep1, StringSplitOptions.RemoveEmptyEntries);
foreach (string g in groups)
{
string p = g;
string[] sep2 = new string[1];
sep2[0] = ",";
int counter = p.Count(x => x == ',');
string[] final_list = new string[counter + 1];
final_list = p.Split(sep2, StringSplitOptions.RemoveEmptyEntries);
foreach (string _f in final_list)
{
if (_f.Trim() == LogInID)
{
_finale = AddLogInIDs(final_list, final_list.Count());
}
}
}
return _finale;
}
private static List<string> AddLogInIDs(string[] final_list, int p)
{
List<string> _finale = new List<string>();
foreach (var item in final_list)
{
_finale.Add(item.Trim());
}
return _finale;
}
Any suggestions will be embraced.
Thanks for your time and patience.
Note: The string will be expanding up to 200 groups
try this..