Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1 = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
Dim pStr() As String
Dim Str, s As String
Dim n As Long
Dim find
n = 0
find = Text2.Text 'BZ
Open Text1 For Input As #1
Do While Not EOF(1)
Line Input #1, s
pStr = Split(s, find)
'由于需要取以#u开头的文字,pStr(0)是以#U前面的,所以舍去然后判断每一段文字是否为空,是否为标点(以为上面的文字段落不是很标准,有两个#U之间是'标点的情况,也有两个#U连在一起的情况)
For i = 1 To UBound(pStr)
If pStr(i) <> "" Then
'判断#U和#U是否相连的,之间是否为空
If InStr(",。、,.", pStr(i)) = 0 Then
'判断#U和#U之间是否仅有一个标点
If Writetxt(App.Path & "\03.txt", find & Mid(pStr(i), 1, 1)) = True Then
'在02.txt中写入每一个有效的#U后面的第一个字,并且判断02.txt中是否已经存在相同的文本。
n = n + 1
End If
End If
End If
Next
Loop
Writetxt App.Path & "\03.txt", "共 " & n & " 个不同数据"
Close #1
End Sub
'***********下面是写入文本的子程序
Private Function Writetxt(tPath As String, txt As String) As Boolean
Dim s2 As String
Writetxt = False
On Error Resume Next
If Dir(tPath) <> "" Then
Open tPath For Input As #1
Else
Open tPath For Output As #1
End If
Do While Not EOF(1)
Line Input #1, s2
If txt = s2 Then Close #1: Exit Function
'如果txt文件中已存在一行同样的字符串,则不写入,退出写入程序
Loop
Close #1
Open tPath For Append As #1
Print #1, txt
Writetxt = True
Close #1
End Function
好久没有用VB了 现在都忘记了,这个应该是do while
loop循环?
我这样应该是不对的 ,
通过open读取txt,一行行读取,寻找关键字符 (text2.text),提取关键字符 #BZ 后的汉子(主要判断是双字节就提取,排除标点比较麻烦),然后输出
大神!求救 我只能做伸手党了 T.T