Split string and display in ASP.Net TextBoxes using C# and VB.Net

Last Reply 6 months ago By pandeyism

Posted 6 months ago

i want to split this 20180526044400022000094 into text box like

201805260444  26-05-2018 04:44 Date textbox

0002          0002     Status Textbox

2000094    2000094  Code Textbox 

please guide thanks...

Posted 6 months ago Modified on 6 months ago

Hey akhter,

Please refer below sample.

HTML

Date :<br />
<asp:TextBox runat="server" ID="txtDate" />
<br />
Status :<br />
<asp:TextBox runat="server" ID="txtStatus" />
<br />
Code:<br />
<asp:TextBox runat="server" ID="txtCode" />

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    string number = "20180526044400022000094";
    txtDate.Text = Convert.ToDateTime(number.Substring(0, 8).Insert(4, "/").Insert(7, "/")).ToString("dd-MM-yyyy")+" "+number.Substring(8, 4).Insert(2, ":");      
    txtStatus.Text = number.Substring(12, 4);
    txtCode.Text = number.Substring(16, 7);
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim number As String = "20180526044400022000094"
    txtDate.Text = Convert.ToDateTime(number.Substring(0, 8).Insert(4, "/").Insert(7, "/")).ToString("dd-MM-yyyy") + " " + number.Substring(8, 4).Insert(2, ":")
    txtStatus.Text = number.Substring(12, 4)
    txtCode.Text = number.Substring(16, 7)
End Sub

Screenshot