من میخوام از یه متن طولانی تعداد دفعات تکرار یک رشته خاص داخل اون متن رو به دست بیارم مثلا اگه عبارت "the land of the dead" رو وارد کنیم و تعداد دفعات حرف "the"رو بخوایم بهمون عدد دو رو برگشت بده.
من میخوام از یه متن طولانی تعداد دفعات تکرار یک رشته خاص داخل اون متن رو به دست بیارم مثلا اگه عبارت "the land of the dead" رو وارد کنیم و تعداد دفعات حرف "the"رو بخوایم بهمون عدد دو رو برگشت بده.
Private Function Repeat(ByVal Str As String, ByVal StrOn As String) As Integer
For i As Integer = 1 To Str.Length
Application.DoEvents()
If Mid(Str, i, StrOn.Length) = StrOn Then Repeat += 1 : i += StrOn.Length - 1
Next
Return Repeat
End Function
یا
MsgBox("the land of the dead the the".Split("the").Length - 1)
بهتر بود اول جستجو میکردی.
سلام
فکر کنم منظورتون از "حرف" کلمه باشه
اگه می خواین یه کلمه رو توی یک فایل TXT جستجو کنید یه راهش اینه که خط به خط فایل رو بخونید و بعدش با یه If اون رشته رو پیدا کنید.
اینم از کدش:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim file As Integer = FreeFile()
FileOpen(file, "c:\1.txt", OpenMode.Input, OpenAccess.Read)
Dim str As String
Dim cnt As Integer
While Not EOF(file)
str = LineInput(file)
If str.Contains(TextBox1.Text) Then
cnt = cnt + 1
End If
End While
FileClose(file)
Label1.Text = cnt
End Sub