ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Split Comma separated string into multiple Column in Windows Application using C# and VB.Net<p>Hey <a class="username" rel="priyajsr">priyajsr</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Code </strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Working Hours&#34;, typeof(string)), new DataColumn(&#34;Ot Hours&#34;, typeof(string)) }); string str = &#34;0-16:02:04,08:00:00-00:10:35,08:00:00-00:10:19,08:00:00-00:25:58,08:00:00-01:29:01&#34;; string[] strsplit = str.Split(&#39;,&#39;); foreach (string item in strsplit) { dt.Rows.Add(item.Split(&#39;-&#39;)[0] == &#34;0&#34; ? &#34;00:00:00&#34; : item.Split(&#39;-&#39;)[0], item.Split(&#39;-&#39;)[1]); } this.dataGridView1.DataSource = dt; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;Working Hours&#34;, GetType(String)), New DataColumn(&#34;Ot Hours&#34;, GetType(String))}) Dim str As String = &#34;0-16:02:04,08:00:00-00:10:35,08:00:00-00:10:19,08:00:00-00:25:58,08:00:00-01:29:01&#34; Dim strsplit As String() = str.Split(&#34;,&#34;c) For Each item As String In strsplit dt.Rows.Add(If(item.Split(&#34;-&#34;c)(0) = &#34;0&#34;, &#34;00:00:00&#34;, item.Split(&#34;-&#34;c)(0)), item.Split(&#34;-&#34;c)(1)) Next Me.dataGridView1.DataSource = dt End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/pFFRLdp.jpg" alt="" width="275" height="233" /></p>https://www.aspforums.net:443/Threads/124395/Split-Comma-separated-string-into-multiple-Column-in-Windows-Application-using-C-and-VBNet/https://www.aspforums.net:443/Threads/124395/Split-Comma-separated-string-into-multiple-Column-in-Windows-Application-using-C-and-VBNet/Fri, 14 Dec 2018 04:36:30 GMTSplit Comma separated string into multiple Column in Windows Application using C# and VB.Net<p>I will try and let you know</p>https://www.aspforums.net:443/Threads/124395/Split-Comma-separated-string-into-multiple-Column-in-Windows-Application-using-C-and-VBNet/https://www.aspforums.net:443/Threads/124395/Split-Comma-separated-string-into-multiple-Column-in-Windows-Application-using-C-and-VBNet/Fri, 14 Dec 2018 04:47:13 GMT