c# - How to find an Index of a string in a list -


so trying retrieve index of first item, in list, begins "whatever", not sure how this.

my attempt (lol):

list<string> txtlines = new list<string>(); //fill list<string> lines txt file. foreach(string str in file.readalllines(filename)) {   txtlines.add(str); } //insert line want add last under tag 'item1'. int index = 1; index = txtlines.indexof(npcid); 

yea know isn't anything, , wrong because seems looking item equal npcid rather line begins it.

if want "startswith" can use findindex

 int index = txtlines.findindex(x => x.startswith("whatever")); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -