This tutorial will show you how to cut string using ASP.NET 2.0 and C#.
This tutorial uses default namespace. The sample will show you how to intercept the character string and restrict the character length. Moreover, it will automatically turn to the newline.
In order to run the example, we will use the btn_cut_Click to trigger the task. The code as following:
| protected void btn_cut_Click(object sender, EventArgs e) { string s=""; } string str = string.Empty; str = txtInputString.Text.Trim(); int len = 0; if (txt_length.Text.Equals("") == false) len = Int32.Parse(txt_length.Text.Trim()); for (int i = 0; i < str.Length; i++) { int r = i % len; }int last = (str.Length / len) * len; if (i != 0 && i <= last) { if (r == 0) }{ s += str.Substring(i - len, len) + "<br>"; }else if (i > last) { s += str.Substring(i - 1); }break; this.lblMessage.Text = s; |
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
The front end CutStringCsharp.aspx page looks something like this:| <div align="left" style="text-align: center"> <table> <tr> </table><td colspan="2" style="width: 200px"> </tr>Input String :</td> <td colspan="1" style="width: 17px"> <asp:TextBox ID="txtInputString" runat="server"></td> <tr> <td colspan="2" style="height: 26px"> </tr>Length:</td> <td colspan="1" style="width: 17px"> <asp:TextBox ID="txt_length" runat="server"></asp:TextBox></td> <tr> <td colspan="3" style="height: 26px"> </tr><asp:Button ID="btn_cut" runat="server" Text="Cut String" OnClick="btn_cut_Click"/></td> <tr> <td colspan="3" style="height: 26px"> </tr><asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label></td> </div> |
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
The flow for the code behind page is as follows| using System; protected void Page_Load(object sender, EventArgs e) } { // This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com }// Visit http://www.AspNetTutorials.com for more ASP.NET Tutorials protected void btn_cut_Click(object sender, EventArgs e) { string s=""; }string str = string.Empty; str = txtInputString.Text.Trim(); int len = 0; if (txt_length.Text.Equals("") == false) len = Int32.Parse(txt_length.Text.Trim()); for (int i = 0; i < str.Length; i++) { int r = i % len; }int last = (str.Length / len) * len; if (i != 0 && i <= last) { if (r == 0) }{ s += str.Substring(i - len, len) + "<br>"; }else if (i > last) { s += str.Substring(i - 1); }break; this.lblMessage.Text = s; |
No comments:
Post a Comment