删除多行文本框中的特定行

时间:2014-04-12 17:28:54

标签: c# .net regex

我有一个Multiline文本框,我可以粘贴网址。 URL将粘贴到字符串变量中。现在我想要的是,来自特定域的URL只能传递给字符串变量。

例如:

http://domain-1.tld/gfdgfd.php?=2135346432
http://domain-2.tld/fsefes.php?=2145312542
http://domain-1.tld/random/folders/iwadaex.php?=2112313543
http://domain-2.tld/igewex.php?=2135464432
http://domain-1.tld/folder/inwadawx.php?=2135546432
http://domain-2.tld/ihtfhtf.php?=2143534432

我有一个Domain 1Domain 2的单选按钮。如果选中Domain 1,则只会将Domain 1中的网址放入变量中,依此类推。

我只需要知道,我如何过滤网址...

2 个答案:

答案 0 :(得分:0)

var result =  textBox1.Text.Split('\n').Where(x => x.Contains(@"http://" + domain)).ToArray();

在评论后修改:

var str = String.Join(Environment.NewLine, result);

答案 1 :(得分:0)

您可以使用Lines属性获取您的行,然后使用Where方法对其进行过滤:

var filteredUrls = textBoxName.Lines.Where(x => x.Contains(someValue)).ToArray();

然后,如果您想要一起显示它们,可以使用String.Join

var output = string.Join(Environment.NewLine, filteredUrls);
相关问题