HGBRD
HGBRD

Reputation: 89

C# String match (result) from .txt file

TEXT.txt:

who     
when   
what   
how

Example.cs:

String example = "what is the time" ;

foreach (string line in File.ReadLines(@"C:\TEXT.txt"))
{
    if (example.Contains(line))
    {
        Messagebox.Show("True, the match is 'what'");
    }
}

I've made a text file, TEXT.txt, and a piece of code that checks if any of the lines in the text file match something in the example string. How do I see what the actual match is? In this case it would be what.

Upvotes: 0

Views: 138

Answers (2)

qqbenq
qqbenq

Reputation: 10460

You can do that:

 Messagebox.Show("True, the match is '" + line + "'");

Upvotes: 2

Oliver
Oliver

Reputation: 36393

Is the "actual match" not just the variable line? Hence:

Messagebox.Show(string.Format("True, the match is '{0}'", line));

Upvotes: 5

Related Questions