This tutorial will show you how to cut string using ASP.NET 2.0 and VB.NET 2005.
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 Sub btn_cut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_cut.Click Dim s As String = "" End Sub Dim str As String = String.Empty str = txtInputString.Text.Trim() Dim len As Integer = 0 If txt_length.Text.Equals("") = False Then len = Int32.Parse(txt_length.Text.Trim()) End IfFor i As Integer = 0 To str.Length Dim r As Integer = i Mod len nextDim last As Integer = (str.Length / len) * len If i <> 0 And i <= last Then If r = 0 Then ElseIf i > last Then s += str.Substring(i - len, len) + "<br>" End Ifs += str.Substring(i - 1) End IfExit For Me.lblMessage.Text = s |
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
The front end CutStringVB.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> |
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
The flow for the code behind page is as follows| Partial Class _Default Inherits System.Web.UI.Page End Class Protected Sub btn_cut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_cut.Click Dim s As String = "" End SubDim str As String = String.Empty str = txtInputString.Text.Trim() Dim len As Integer = 0 If txt_length.Text.Equals("") = False Then len = Int32.Parse(txt_length.Text.Trim()) End IfFor i As Integer = 0 To str.Length Dim r As Integer = i Mod len nextDim last As Integer = (str.Length / len) * len If i <> 0 And i <= last Then If r = 0 Then ElseIf i > last Then s += str.Substring(i - len, len) + "<br>" End Ifs += str.Substring(i - 1) End IfExit For Me.lblMessage.Text = s Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com End Sub' Visit http://www.AspNetTutorials.com for more ASP.NET Tutorials |
No comments:
Post a Comment