如何用VB统计TXT文本中某个字母(忽略大小写)出现次数
在文本框Text1中输入一个字母,单击“统计并保存”按钮,将统计出个人文件夹内paperin.txt文件中该字母出现的指数(忽略大小写),并将出现的个数保存到个人文件夹中...
在文本框Text1中输入一个字母,单击“统计并保存”按钮,将统计出个人文件夹内paperin.txt文件中该字母出现的指数(忽略大小写),并将出现的个数保存到个人文件夹中的paperout.txt文件中。
展开
2个回答
展开全部
Private Sub Command1_Click()
Dim S As String, S1 As String, N As Long
S1 = Text1.Text
Open "文件路径+文件名+后缀名" For Binary As #1
S = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
N = Len(S)
N = N - Len(Replace(S, S1, "", , , vbTextCompare))
Open "保存个数的文件路径+文件名+后缀名" For Append As #1
Print #1, N
Close #1
End Sub
展开全部
Private Sub Command1_Click()
Dim i, j As Integer
Dim a As String
Open App.Path + "\paperin.txt" For Input As #1
Do
Input #1, a
For i = 1 To Len(a)
If LCase(Mid(a, i, 1)) = LCase(Text1.Text) Then j = j + 1
Next i
Loop While Not EOF(1)
Open App.Path + "\paperout.txt" For Output As #2
Print #2, j
Close #2
j = 0
Close #1
End Sub
Dim i, j As Integer
Dim a As String
Open App.Path + "\paperin.txt" For Input As #1
Do
Input #1, a
For i = 1 To Len(a)
If LCase(Mid(a, i, 1)) = LCase(Text1.Text) Then j = j + 1
Next i
Loop While Not EOF(1)
Open App.Path + "\paperout.txt" For Output As #2
Print #2, j
Close #2
j = 0
Close #1
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询