Imports System.Text.RegularExpressions
Public Class Form1
Public lastMatch As Integer = 0
Private Sub Load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadB.Click
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "H:\REgExEditor\REgExEditor\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
' Insert code to read the stream here.
Dim sr As New StreamReader(myStream)
Me.Originaltb.Text = sr.ReadToEnd()
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
End Sub
Private Sub regexExpression_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles regexExpression.TextChanged
lastMatch = 0
End Sub
Private Sub Match_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Match.Click
Me.Originaltb.ReadOnly = True
Me.Originaltb.Focus()
'Me.Originaltb.SelectionStart = 100
' Me.Originaltb.SelectionLength = 25
'Me.Originaltb.Select(100, 25)
Dim reg As New Regex(Me.regexExpression.Text.Trim())
Dim searchString As String = Me.Originaltb.Text
Dim match As Match = reg.Match(searchString, lastMatch)
If match.Success Then
Me.Originaltb.Select(match.Index, Me.regexExpression.Text.Trim().Length)
lastMatch = match.Index + Me.regexExpression.Text.Trim().Length
' Me.Originaltb.Invalidate()
End If
End Sub
Private Sub TransfomB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransfomB.Click
Dim reg As New Regex(Me.regexExpression.Text.Trim())
Dim searchString As String = Me.Originaltb.Text
Me.TransformBox.Text = reg.Replace(searchString, Me.replaceTB.Text.Trim())
End Sub
End Class
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.TabControl1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.Originaltb = New System.Windows.Forms.TextBox
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.regexExpression = New System.Windows.Forms.TextBox
Me.ToolStrip1 = New System.Windows.Forms.ToolStrip
Me.LoadB = New System.Windows.Forms.ToolStripButton
Me.Save = New System.Windows.Forms.ToolStripButton
Me.SaveAs = New System.Windows.Forms.ToolStripButton
Me.TransformBox = New System.Windows.Forms.TextBox
Me.TransfomB = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Match = New System.Windows.Forms.Button
Me.replaceTB = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.TabControl1.SuspendLayout()
Me.TabPage1.SuspendLayout()
Me.TabPage2.SuspendLayout()
Me.ToolStrip1.SuspendLayout()
Me.SuspendLayout()
'
'TabControl1
'
Me.TabControl1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Location = New System.Drawing.Point(-2, 57)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(708, 335)
Me.TabControl1.TabIndex = 0
'
'TabPage1
'
Me.TabPage1.Controls.Add(Me.Originaltb)
Me.TabPage1.Location = New System.Drawing.Point(4, 22)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage1.Size = New System.Drawing.Size(700, 309)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "TabPage1"
Me.TabPage1.UseVisualStyleBackColor = True
'
'Originaltb
'
Me.Originaltb.Dock = System.Windows.Forms.DockStyle.Fill
Me.Originaltb.Location = New System.Drawing.Point(3, 3)
Me.Originaltb.Multiline = True
Me.Originaltb.Name = "Originaltb"
Me.Originaltb.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.Originaltb.Size = New System.Drawing.Size(694, 303)
Me.Originaltb.TabIndex = 1
'
'TabPage2
'
Me.TabPage2.Controls.Add(Me.TransformBox)
Me.TabPage2.Location = New System.Drawing.Point(4, 22)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage2.Size = New System.Drawing.Size(700, 309)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "TabPage2"
Me.TabPage2.UseVisualStyleBackColor = True
'
'regexExpression
'
Me.regexExpression.Location = New System.Drawing.Point(56, 31)
Me.regexExpression.Name = "regexExpression"
Me.regexExpression.Size = New System.Drawing.Size(300, 20)
Me.regexExpression.TabIndex = 0
'
'ToolStrip1
'
Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.LoadB, Me.Save, Me.SaveAs})
Me.ToolStrip1.Location = New System.Drawing.Point(0, 0)
Me.ToolStrip1.Name = "ToolStrip1"
Me.ToolStrip1.Size = New System.Drawing.Size(702, 25)
Me.ToolStrip1.TabIndex = 1
Me.ToolStrip1.Text = "ToolStrip1"
'
'LoadB
'
Me.LoadB.Image = CType(resources.GetObject("LoadB.Image"), System.Drawing.Image)
Me.LoadB.ImageTransparentColor = System.Drawing.Color.Magenta
Me.LoadB.Name = "LoadB"
Me.LoadB.Size = New System.Drawing.Size(53, 22)
Me.LoadB.Text = "Load"
'
'Save
'
Me.Save.Image = CType(resources.GetObject("Save.Image"), System.Drawing.Image)
Me.Save.ImageTransparentColor = System.Drawing.Color.Magenta
Me.Save.Name = "Save"
Me.Save.Size = New System.Drawing.Size(51, 22)
Me.Save.Text = "Save"
'
'SaveAs
'
Me.SaveAs.Image = CType(resources.GetObject("SaveAs.Image"), System.Drawing.Image)
Me.SaveAs.ImageTransparentColor = System.Drawing.Color.Magenta
Me.SaveAs.Name = "SaveAs"
Me.SaveAs.Size = New System.Drawing.Size(64, 22)
Me.SaveAs.Text = "SaveAs"
'
'TransformBox
'
Me.TransformBox.Dock = System.Windows.Forms.DockStyle.Fill
Me.TransformBox.Location = New System.Drawing.Point(3, 3)
Me.TransformBox.Multiline = True
Me.TransformBox.Name = "TransformBox"
Me.TransformBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.TransformBox.Size = New System.Drawing.Size(694, 303)
Me.TransformBox.TabIndex = 2
'
'TransfomB
'
Me.TransfomB.Location = New System.Drawing.Point(615, 29)
Me.TransfomB.Name = "TransfomB"
Me.TransfomB.Size = New System.Drawing.Size(75, 23)
Me.TransfomB.TabIndex = 2
Me.TransfomB.Text = "Transform"
Me.TransfomB.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 34)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(38, 13)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Regex"
'
'Match
'
Me.Match.Location = New System.Drawing.Point(534, 28)
Me.Match.Name = "Match"
Me.Match.Size = New System.Drawing.Size(75, 23)
Me.Match.TabIndex = 4
Me.Match.Text = "Match"
Me.Match.UseVisualStyleBackColor = True
'
'replaceTB
'
Me.replaceTB.Location = New System.Drawing.Point(428, 34)
Me.replaceTB.Name = "replaceTB"
Me.replaceTB.Size = New System.Drawing.Size(100, 20)
Me.replaceTB.TabIndex = 5
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(372, 37)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(47, 13)
Me.Label2.TabIndex = 6
Me.Label2.Text = "Replace"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(702, 389)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.replaceTB)
Me.Controls.Add(Me.Match)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TransfomB)
Me.Controls.Add(Me.regexExpression)
Me.Controls.Add(Me.ToolStrip1)
Me.Controls.Add(Me.TabControl1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.TabControl1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
Me.TabPage1.PerformLayout()
Me.TabPage2.ResumeLayout(False)
Me.TabPage2.PerformLayout()
Me.ToolStrip1.ResumeLayout(False)
Me.ToolStrip1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
Friend WithEvents LoadB As System.Windows.Forms.ToolStripButton
Friend WithEvents regexExpression As System.Windows.Forms.TextBox
Friend WithEvents Save As System.Windows.Forms.ToolStripButton
Friend WithEvents SaveAs As System.Windows.Forms.ToolStripButton
Friend WithEvents Originaltb As System.Windows.Forms.TextBox
Friend WithEvents TransformBox As System.Windows.Forms.TextBox
Friend WithEvents TransfomB As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Match As System.Windows.Forms.Button
Friend WithEvents replaceTB As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
End Class
No comments:
Post a Comment