c# - Get the index of Array List -
i have question array list in c#
i have array following elements:
- lqi request - 0123456 - lqi request - 456789 - lqi request - 6789 .....
now want is, find strings lqi request
, , string next it, that's i've tried far:(index global variable)
if(mystring.contains("lqi")) { index= stored_data.indexof(mystring); } messagebox.show(index.tostring()); messagebox.show(stored_data[index+1].tostring());
verytime run code, index stays same. should be: 0,2,4
please help
list<string> data = new list<string> { "- lqi request", "- 0123456", "- lqi request", "- 456789", "- lqi request", "- 6789" }; var result = data.select((x, i) => // x element, index { if (x.contains("lqi")) if(i + 1 < data.count) // index inside bounds of array return data[i + 1].substring(2); // don't take "- " return string.empty; }).where(x => !string.isnullorempty(x)) // ignore empty results .toarray(); // result: ["0123456", "456789", "6789"]
Comments
Post a Comment