⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Mastering VBNet Include Source Code
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'TextBox1
        '
        Me.TextBox1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox1.Location = New System.Drawing.Point(8, 8)
        Me.TextBox1.MaxLength = 0
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.TextBox1.Size = New System.Drawing.Size(488, 256)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = ""
        '
        'Button1
        '
        Me.Button1.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button1.Location = New System.Drawing.Point(504, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(130, 48)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Reverse Text (StringBuilder)"
        '
        'Button2
        '
        Me.Button2.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button2.Location = New System.Drawing.Point(504, 64)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(130, 48)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "Reverse Text (String)"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(640, 269)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1, Me.TextBox1})
        Me.Name = "Form1"
        Me.Text = "String Reversal"
        Me.ResumeLayout(False)

    End Sub

#End Region

    ' To see how much faster you can manipulate string with the StringBuilder
    ' object, paste a fairly large amount of text on the TextBox (several KBytes)
    ' The event handlers display the time it took to reverse the string 
    ' in the Output window. The value you see is the value of a TimeSpan object
    ' that represents the difference between the start and end times.
    '
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim STR As New System.Text.StringBuilder()
        Dim txtLen As Integer = Len(TextBox1.Text)
        STR.Capacity = txtLen
        STR.Append(TextBox1.Text)
        Dim ichar As Integer
        Dim chr As Char
        Dim T1 As TimeSpan
        Dim TStart As Date
        TStart = Now()
        For ichar = 0 To CInt(STR.Length / 2 - 1)
            chr = STR.Chars(ichar)
            STR.Chars(ichar) = STR.Chars(txtLen - ichar - 1)
            STR.Chars(txtLen - ichar - 1) = chr
        Next
        Dim revCrLf As String
        revCrLf = vbCrLf.Chars(1) & vbCrLf.Chars(0)
        STR.Replace(revCrLf, vbCrLf)
        T1 = Now().Subtract(TStart)
        Console.WriteLine(T1)
        TextBox1.Text = STR.ToString
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim T1 As TimeSpan
        Dim TStart As Date
        TStart = Now()
        Dim txt As String
        txt = TextBox1.Text
        Dim txtLen As Integer = Len(txt)
        Dim aChar As String
        Dim iChar As Integer
        For ichar = 1 To CInt(txtLen / 2)
            aChar = Mid(txt, ichar, 1)
            Mid(txt, ichar, 1) = Mid(txt, txtLen - ichar - 1, 1)
            Mid(txt, txtLen - ichar - 1) = aChar
        Next
        T1 = Now().Subtract(TStart)
        Console.WriteLine(T1)
        Dim revCrLf As String
        revCrLf = vbCrLf.Chars(1) & vbCrLf.Chars(0)
        txt = txt.Replace(revCrLf, vbCrLf)
        TextBox1.Text = txt
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -