爱人的谎言小冬和小秋:vb 字符串处理

来源:百度文库 编辑:高考问答 时间:2024/05/04 07:08:29
目的:将指定文本文件中的 text1 TEXT2等 的行进行处理
其格式为
TEXT1=AAAAA
TEXT2=BBBBB
目前实现方法:将文件逐行读入,判断处理,写入RICHTEXTBOX1直至读完。。
将RICHTEXTBOX1的内容写入文件。。

!!遇到的问题是有800多K的文本文件,处理起来效率很低。。

Private Sub Command3_Click()
Dim str As String

Command3.Enabled = False

Command3.Caption = "正在修改 QQ19443156"

RichTextBox1.Text = ""

Open Text2.Text For Input As #1
If LOF(1) > 0 Then
While Not EOF(1)
X = DoEvents
Line Input #1, str

If Check1.Value = 1 And InStr(str, Check1.Caption) Then str = Check1.Caption + " " + Text1.Text + "\flyers"
If Check2.Value = 1 And InStr(str, Check2.Caption) Then str = Check2.Caption + " " + Text1.Text + "\titles"
If Check3.Value = 1 And InStr(str, Check3.Caption) Then str = Check3.Caption + " " + Text1.Text + "\icons"
If Check4.Value = 1 And InStr(str, Check4.Caption) Then str = Check4.Caption + " " + Text1.Text + "\roms"
If Check5.Value = 1 And InStr(str, Check5.Caption) Then str = Check5.Caption + " " + Text1.Text + "\samples"
If Check6.Value = 1 And InStr(str, Check6.Caption) Then str = Check6.Caption + " " + Text1.Text + "\artwork"
If Check7.Value = 1 And InStr(str, Check7.Caption) Then str = Check7.Caption + " " + Text1.Text + "\snap"

RichTextBox1.Text = RichTextBox1.Text + str + Chr(13)

Wend
End If
Close #1
Open Text2.Text For Output As #2
Print #2, RichTextBox1.Text
Close #2
Command3.Enabled = True
Command3.Caption = "修改....."

End Sub
提出解决方案

RichTextBox1.Text = RichTextBox1.Text + str + Chr(13)

这句话是效率低下的根源,如果richtextbox.text太大了,它的加法将会慢得要命。你应该用flexgrid一类的,它的additem(貌似,具体不记得了)效率很高,跟总的数据量没有关系

把richtextbox换成flexgrid,把richtextbox.text=richtextbox.text+str换成flexgrid.additem(str),回车符chr(13)不需要了

以上。
用过的老狼