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
 

nicanil

Client
Регистрация
06.03.2016
Сообщения
2 242
Благодарностей
1 807
Баллы
113
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;
 

Saeedgh837

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

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