Program to split the given string in asp.net
like that you can enter the abc1288hbgg23 so split this string in two parts one is string and one is integer..
Asp.net code
<asp:TextBox ID="txtname" runat="server">
</asp:TextBox>
<asp:Button ID="btn" runat="server" Text="click" onclick="btn_Click" /><br /><br />
<asp:Label ID="lbmsg" runat="server" Visible="false">String Part..</asp:Label><br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="lblmsg1" runat="server" Visible="false">Integer Part..</asp:Label><br /><br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<asp:Label ID="lblmsg2" runat="server" Visible="false">Other Part..</asp:Label><br /><br />
<asp:Label ID="Label3" runat="server"></asp:Label>
C# code...
Label lb = new Label();
Label lb1 = new Label();
protected void btn_Click(object sender, EventArgs e)
{
string nm = txtname.Text;
lbmsg.Visible = true;
lblmsg1.Visible = true;
for (int i = 0; i < nm.Length; i++)
{
if (nm[i] >= 48 && nm[i] > 58)
{
lb.Text += nm[i];
}
else
{
lb1.Text += nm[i];
}
}
Label1.Text = lb.Text;
Label2.Text = lb1.Text;
}
like that you can enter the abc1288hbgg23 so split this string in two parts one is string and one is integer..
Asp.net code
<asp:TextBox ID="txtname" runat="server">
</asp:TextBox>
<asp:Button ID="btn" runat="server" Text="click" onclick="btn_Click" /><br /><br />
<asp:Label ID="lbmsg" runat="server" Visible="false">String Part..</asp:Label><br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br /><br />
<asp:Label ID="lblmsg1" runat="server" Visible="false">Integer Part..</asp:Label><br /><br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<asp:Label ID="lblmsg2" runat="server" Visible="false">Other Part..</asp:Label><br /><br />
<asp:Label ID="Label3" runat="server"></asp:Label>
C# code...
Label lb = new Label();
Label lb1 = new Label();
protected void btn_Click(object sender, EventArgs e)
{
string nm = txtname.Text;
lbmsg.Visible = true;
lblmsg1.Visible = true;
for (int i = 0; i < nm.Length; i++)
{
if (nm[i] >= 48 && nm[i] > 58)
{
lb.Text += nm[i];
}
else
{
lb1.Text += nm[i];
}
}
Label1.Text = lb.Text;
Label2.Text = lb1.Text;
}
No comments:
Post a Comment