-5
string s = textBox1.Text;
string[] lines = s.Split(Environment.NewLine.ToCharArray());

foreach (string l in lines)
{
    if (Regex.IsMatch(lines.(Here when i select .ToString() i get no o/p), pattern))
    {
        textBox3.Text = textBox3.Text + l + Environment.NewLine+;
    }
}

例如,如果输入是:

Processing \\Users\\bhargava\\Desktop\New.txt
Processing \\Users\\bhargava\\Desktop\\New2.txt
<get process by id>
Processing \\Users\\bhargava\\Desktop\New3.txt
<get element by id>
Processing \\Users\\bhargava\\Desktop\\New4.txt

输出是:

Processing \\Users\\bhargava\\Desktop\New.txt
Processing \\Users\\bhargava\\Desktop\\New2.txt

Processing \\Users\\bhargava\\Desktop\New3.txt

Processing \\Users\\bhargava\\Desktop\\New4.txt
4

1 回答 1

2

您不需要正则表达式。

http://msdn.microsoft.com/en-us/library/k8b1470s.aspx

String.IndexOf(String) 报告此实例中指定字符串第一次出现的从零开始的索引。如果此实例中未出现字符串,则返回 -1。

例如

if (l.IndexOf("Processing") == 0)
{
    //do stuff
}

(不过,作为参考,正则表达式只是Processing

于 2013-05-10T00:05:10.653 回答