consolidating two lists?

ynxd

Новичок
Регистрация
12.02.2015
Сообщения
12
Благодарностей
2
Баллы
3
Hypothetically I have two lists:
List 1 (Name: Links)
Код:
google.com/a1
google.com/a2
google.com/a3
ebay.com/a4
ebay.com/a5
ebay.com/a6
List 2 (Name: Bad Word Filter)
Код:
a2
a3
a4
-----------------------

In reality my two lists have hundreds of lines each. How would I go about filtering "List 1" to remove any lines that contain lines from "List 2"?

The result I wish to be left with in this example is:
List
Код:
google.com/a1
ebay.com/a5
ebay.com/a6
 
Последнее редактирование:

LexxWork

Client
Регистрация
31.10.2013
Сообщения
1 190
Благодарностей
786
Баллы
113
C#:
var list = project.Lists["list"];
var bad_words = project.Lists["bad_words"];
var regexp_string = "(?<=[^/]+/)(";

if (bad_words.Count == 0) return "ok";

for(var i = 0; i < bad_words.Count-1; i++)
    regexp_string += System.Text.RegularExpressions.Regex.Escape(bad_words[i])+"|";
regexp_string += System.Text.RegularExpressions.Regex.Escape(bad_words.Last())+")";

var regex = new System.Text.RegularExpressions.Regex(regexp_string);

for(var i = 0; i < list.Count; i++){
    if(regex.IsMatch(list[i]))
        list.RemoveAt(i--);
}
//return string.Join("\n", list.ToArray()); //look the result
 

Tobbe

Client
Регистрация
01.08.2013
Сообщения
428
Благодарностей
148
Баллы
43
Or if you prefer to use actions instead of C# it can be done like this, along with many other ways.
 

Вложения

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