I have a text file as shown below.
NO: 1
ITEM: Device A
MESSAGE: This item was selected.
NO: 2
ITEM: Device B
MESSAGE: Exception: Could not find the item.
Exception thrown :
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
NO: 3
ITEM: Device C
MESSAGE: This item was selected.
In this program, I need to remove the info that not starts with the specific word and
make it in a group of 3. I stuck at here after remove the info that did not start with specific word. I try to use
string.Join but I cant get the result that I want.
Final result should look like this:
NO: 1,ITEM: Device A,MESSAGE: This item was selected.
NO: 2,ITEM: Device B,MESSAGE: Exception: Could not find the item.
NO: 3,ITEM: Device C,MESSAGE: This item was selected.
What I have tried:
string[] lines = myInput.Split(new[] { "\n" }, StringSplitOptions.None);
for (int i = 0; i < lines.Count(); i++)
{
if (lines[i].StartsWith("NO:") | lines[i].StartsWith("ITEM:") | lines[i].StartsWith("MESSAGE:"))
{
log.Info(lines[i]);
var r = lines[i].Split(new[] { "" }, StringSplitOptions.None);
for (int m = 0; m < lines[i].Length; m += 3)
{
var r = string.Join(" ", lines.Skip(m).Take(3));
log.Info(r);
}
}
}
I have no idea how to continue with the line[i] and join it together as a group of 3. Please advise.