jeudi 16 juin 2016

C# Find next occurrence of a certain string in a list

I'm trying to find the next occurrence of a string in a list that is created dynamically. First I create the list with buttons that save text to a txt file and then divide the file with "," in to a list and by clicking items in the list, I update a textview item next to the list.

The var it = lstv.GetItemAtPosition(e.Position); gives the position on where to start searching for the next string. The next string is one of two possibilities.

var it = lstv.GetItemAtPosition(e.Position);

if(it.ToString() == "string1" || it.ToString() == "string2")
{
//Some code here
}

List

string content;
using (var streamReader = new StreamReader(filename))
{
content = streamReader.ReadToEnd();
}
content = content.TrimEnd(',');
char[] delimiterChars = { ',' }; 
data = content.Split(delimiterChars);
var myAdapter = new ArrayAdapter(this, Resource.Layout.TextViewItem, data);
lstv.Adapter = myAdapter;

The suggestions I have found only get the first or last occurrence, but I have multiple occurrences of the values and I need to get next occurrence from the clicked position

Edit: Should have mentioned there are X number of items between the the starting position and the string I would want get.

Aucun commentaire:

Enregistrer un commentaire