多个.frm文件的模式匹配处理
我有多个 VB6 .frm
文件。请参阅下面的示例。我想从代码中去掉函数和子函数,只留下表单设计。
我需要做的是找到以“Attribute”开头的最后一行,因为在该行之后,所有其他内容都应该被删除。
使用模式匹配或类似的东西,如何处理 .frm
文件,以便删除最后一个属性行之后的所有内容?如果我正在遍历一个文件,我如何知道最后一个属性行在哪里?
.frm
文件示例:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1800
TabIndex = 1
Top = 1320
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 360
TabIndex = 0
Text = "Text1"
Top = 240
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Text1.Text = "Hello World"
End Sub
Private Sub Form_Load()
Text1.BackColor = vbBlue
End
I have multiple VB6 .frm
files. See example below. I want to strip away the functions and subs from the code and leave only the form design.
What I need to do is find the last line starting with "Attribute" because after this line everything further should be deleted.
Using pattern matching or something similar, how can I process the .frm
files so that everything after the last Attribute line is deleted? If I am traversing through a file, how can I tell where the last Attribute line is?
Example of .frm
file:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1800
TabIndex = 1
Top = 1320
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 360
TabIndex = 0
Text = "Text1"
Top = 240
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Text1.Text = "Hello World"
End Sub
Private Sub Form_Load()
Text1.BackColor = vbBlue
End
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要 2 条规则:
1)如果行以“属性”开头,则不要删除。
2) 如果行以“属性”开头,则设置一个标志以开始删除所有后续行。
规则 #1 将阻止您删除后续的属性行,并且在您遇到的第一个属性之后不应该保留任何内容,除非它是一个属性。
You just need 2 rules:
1) If line starts with 'Attribute' then don't delete.
2) If line starts with 'Attribute' set a flag to start deleting all subsequent lines.
Rule #1 will prevent you from deleting subsequent Attribute lines, and there should be nothing you want to keep after the first Attribute you encounter unless it's an Attribute.