Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This meets your requirements as stated, and uses LINQ (since your question was tagged LINQ), but is not necessarily <em>best</em>:</p> <pre><code>class Program { static void Main(string[] args) { List&lt;string&gt; inputs = new List&lt;string&gt; { "FirstName,LastName,Title,BirthDate,HireDate,City,Region", "Nancy,Davolio,Sales Representative,1948-12-08,1992-05-01,Seattle,WA", "Andrew,Fuller,Vice President Sales,1952-02-19,1992-08-14,Tacoma,WA", "Janet,Leverling,Sales Representative,1963-08-30,1992-04-01,Kirkland,WA", "Margaret,Peacock,Sales Representative,1937-09-19,1993-05-03,Redmond,WA", "Steven,Buchanan,Sales Manager,1955-03-04,1993-10-17,London,NULL", "Michael,Suyama,Sales Representative,1963-07-02,1993-10-17,London,NULL", "Robert,King,Sales Representative,1960-05-29,1994-01-02,London,NULL", "Laura,Callahan,Inside Sales Coordinator,1958-01-09,1994-03-05,Seattle,WA", "Anne,Dodsworth,Sales Representative,1966-01-27,1994-11-15,London,NULL" }; // TODO: These widths would presumably be configurable List&lt;int&gt; widths = new List&lt;int&gt; { 12, 22, 32, 13, 12, 17, 8 }; List&lt;string&gt; outputs = inputs.Select(s =&gt; ToFixedWidths(s, ',', widths)).ToList(); outputs.ForEach(s =&gt; System.Diagnostics.Debug.WriteLine(s)); Console.ReadLine(); } private static string ToFixedWidths(string s, char separator, List&lt;int&gt; widths) { List&lt;string&gt; split = s.Split(separator).ToList(); // TODO: Error handling - what if there are more/less separators in // string s than we have width values? return string.Join(String.Empty, split.Select((ss, i) =&gt; ss.PadRight(widths[i], ' ')).ToArray()); } } </code></pre> <p>In a production scenario though I'd expect to see this data read into an appropriate <code>Person</code> class, as Matt recommended in his answer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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