Find Index Of a line contains "a word " in a list

Saeedgh837

Client
Регистрация
09.04.2019
Сообщения
56
Реакции
1
Баллы
8
hi guys

I have a list like this below:

book is good
pencil is made by wood
door is open
window is closed


any way to find the Index of one of them with searching a word like Contains "book"?
I need to search for "book"
answer must be: "0" (Which is its Line number in the list)

i already got a hand with this method in C#:
C#:
Развернуть Свернуть Копировать
return project.Lists["yourListName"].IndexOf("book");

but this code needs to search with the whole sentence to give back the index number.

thank you
 
C#:
Развернуть Свернуть Копировать
string listName = "keys";
string keyword = "book";


var list = project.Lists[listName];
int result = -1;

for (int i=0; i<list.Count; i++)
{
    if (list[i].Contains(keyword))
    {
        result = i;
        break;
    }
}

return result;
 
C#:
Развернуть Свернуть Копировать
string listName = "keys";
string keyword = "book";


var list = project.Lists[listName];
int result = -1;

for (int i=0; i<list.Count; i++)
{
    if (list[i].Contains(keyword))
    {
        result = i;
        break;
    }
}

return result;

thanks a lot, it works like a charm!
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)