所以我试图做的是检索第一个项目,在列表中,以“无论”开头的索引,我不知道如何做到这一点。如何在列表中找到一个字符串的索引
我尝试(笑):
List<string> txtLines = new List<string>();
//Fill a List<string> with the lines from the txt file.
foreach(string str in File.ReadAllLines(fileName)) {
txtLines.Add(str);
}
//Insert the line you want to add last under the tag 'item1'.
int index = 1;
index = txtLines.IndexOf(npcID);
是啊,我知道这是不是真的事,那是错误的,因为它似乎在寻找那等于npcID,而不是行中的项目从它开始。
它确实会显示字符串的索引。请查看http://www.dotnetperls.com/indexof – Sunny 2013-05-14 03:34:19
究竟是什么问题?如果'txtLines'是一个文本框,只需执行'txtLines.Text.IndexOf(ncpID)'。 – Matthew 2013-05-14 03:35:57
对不起,只是修复它,出于某种原因代码没有粘贴。哦,很好的修复 – 2013-05-14 03:37:54