C# – Getting line of text after specific string in C#

c++

I am reading contents of a file that looks something like this

[1]
Message=my string here
EffDate=1/1/1995
DeactDate= 
Modified= 
Note=

[2]
Message=my other string here
EffDate=1/1/1995
DeactDate= 
Modified= 
Note=

I want to get the string after Message= but only to the end of the line. I do not want any of the dates or notes or anything.

I was hoping to put both messages into an array of strings or something like that. Is there any way to do it?

Any help is appreciated.

Best Solution

This is a working code you need:

var d = File.ReadAllLines(filePath);
            var t = d.Where(g => g.Contains("Message"));
            string[] splited;
            foreach (var item in t)
            {
                splited = item.Split(new string[] { "Message=" }, StringSplitOptions.None);
                Console.WriteLine(splited[1]);
            }

Let me know if you have any confusion.