Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Depending on the exact content and guarantee of format of a CSV file, for speed and ease, sometimes using <a href="http://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.71%29.aspx" rel="nofollow"><code>split</code></a> on the <code>,</code> is the easiest and fastest way to parse the file. Your Name col includes a <code>,</code> that is not a delimiter, which adds a little bit of complication though it is still trivial to handle that case assuming the name always contains 1 <code>,</code>.</p> <p>There are libraries to parse CSV files, which can be useful. Assuming you don't need to handle all files that conform to the CSV spec I feel that they are overkill. With all that said you can use the following <a href="http://www.regular-expressions.info/dotnet.html" rel="nofollow">regular expression</a> to easily parse the CSV file with named groups for convince:</p> <p><code>"(?&lt;Name&gt;[^"]+?)",(?&lt;UserName&gt;[^,]+?),(?&lt;RowType&gt;[^,]+?),(?&lt;StartDate&gt;[^,]+?),(?&lt;StartTime&gt;[^,]+?),(?&lt;EndTime&gt;[^,]+?),(?&lt;EndDate&gt;[^,]+?),(?&lt;SegmentStartDate&gt;[^,]+?),(?&lt;Type&gt;\w+)</code></p> <p>That will create named capture groups that you can then use to output to your new CSV file like so:</p> <pre><code>Dim ResultList As StringCollection = New StringCollection() Try Dim RegexObj As New Regex("""(?&lt;Name&gt;[^""]+?)"",(?&lt;UserName&gt;[^,]+?),(?&lt;RowType&gt;[^,]+?),(?&lt;StartDate&gt;[^,]+?),(?&lt;StartTime&gt;[^,]+?),(?&lt;EndTime&gt;[^,]+?),(?&lt;EndDate&gt;[^,]+?),(?&lt;SegmentStartDate&gt;[^,]+?),(?&lt;Type&gt;\w+)", RegexOptions.IgnoreCase) Dim MatchResult As Match = RegexObj.Match(SubjectString) While MatchResult.Success 'Append to new CSV file - MatchResult.Groups("groupname").Value 'Name = MatchResult.Groups("Name").Value 'Start Time = MatchResult.Groups("StartTime").Value 'End Time = MatchResult.Groups("EndTime").Value 'Etc... End While Catch ex As ArgumentException 'Syntax error in the regular expression End Try </code></pre> <p>See <a href="http://msdn.microsoft.com/en-us/library/hs600312%28v=vs.71%29.aspx" rel="nofollow">.NET Framework Regular Expressions</a> on MSDN for more information.</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.
    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