Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based on the info you've given us, you can just take a <a href="http://msdn.microsoft.com/en-us/library/aka44szs.aspx" rel="nofollow noreferrer">substring</a> from 0 to the <a href="http://msdn.microsoft.com/en-us/library/k8b1470s.aspx" rel="nofollow noreferrer">index of the <code>]</code></a>.</p> <pre><code>string ExtractFirstColumn(line) { int index = line.IndexOf("]"); string firstColumn = line.Substring(0, index + 1); return firstColumn; } </code></pre> <p>That will give you the whole first column, as you asked for. You would then <a href="http://msdn.microsoft.com/en-us/library/bb548891.aspx" rel="nofollow noreferrer">do this for each line</a>. Then, if these are all in a <a href="http://msdn.microsoft.com/en-us/library/dd383503.aspx" rel="nofollow noreferrer">single file</a>, you can say:</p> <pre><code>var lines = File.ReadLines(log); var firstColumns = lines.Select(line =&gt; ExtractFirstColumn(line)); </code></pre> <p>Then, if you need to <a href="http://msdn.microsoft.com/en-us/library/system.string.split.aspx" rel="nofollow noreferrer">split</a> the first column, you can split on <code>' '</code>:</p> <pre><code>var tokens = firstColumn.Split(' '); // tokens[0].Remove("[") is the data // tokens[1] is the time // tokens[2].Remove("]") is "CDF" </code></pre> <p>If you need more than the first column, as you're <em>now</em> indicating in your comments<sup>1</sup>, you'll have to move a little differently:</p> <pre><code>string[] ExtractColumns(string line) { int index = line.IndexOf("]"); string firstColumn = line.Substring(0, index + 1); string[] lastTwoColumns = line.Substring(index + 2).Split(' '); return new string[] { firstColumn, lastTwoColumns[1], lastTwoColumns[2] }; } </code></pre> <p>I'm only going off the two examples you've given us, but I'd start with this very simple, maintainable approach absent new information.</p> <p><sup>1</sup>: This is why the <a href="https://stackoverflow.com/help/how-to-ask">guidelines for how to ask a question</a> say to <em>be specific</em>. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload