(11-08-24, 01:26 AM)Amir_Alzubidy كتب : حل رقم (1)
PHP كود :
Imports System.IO
Public Class Form1
' افترض أن لديك 3 TextBox: txtSearch, txtResults, txtCount
' و Button واحد لتنفيذ البحث
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim searchTerm As String = txtSearch.Text.Trim()
Dim filePath As String = "C:\path\to\CORAN.txt" ' قم بتحديث المسار إلى المسار الصحيح للملف
If String.IsNullOrEmpty(searchTerm) Then
MessageBox.Show("يرجى إدخال كلمة البحث.")
Return
End If
If Not File.Exists(filePath) Then
MessageBox.Show("الملف النصي غير موجود.")
Return
End If
Dim content As String = File.ReadAllText(filePath)
Dim lines() As String = content.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
Dim results As New Text.StringBuilder()
Dim count As Integer = 0
For Each line As String In lines
Dim index As Integer = 0
While (index = line.IndexOf(searchTerm, index, StringComparison.OrdinalIgnoreCase)) >= 0
count += 1
' العثور على الكلمة السابقة
Dim startIndex As Integer = Math.Max(0, index - 50)
Dim previousText As String = line.Substring(startIndex, index - startIndex).Trim()
Dim previousWord As String = previousText.Split(" "c).LastOrDefault()
' إضافة النتيجة إلى نتائج البحث
results.AppendLine($"{previousWord} {searchTerm}")
' متابعة البحث في نفس السطر
index += searchTerm.Length
End While
Next
txtResults.Text = results.ToString()
txtCount.Text = count.ToString()
End Sub
End Class
حل اخر باستخدام الريجكس
PHP كود :
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
' افترض أن لديك 3 TextBox: txtSearch, txtResults, txtCount
' و Button واحد لتنفيذ البحث
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim searchTerm As String = txtSearch.Text.Trim()
Dim filePath As String = "C:\path\to\CORAN.txt" ' قم بتحديث المسار إلى المسار الصحيح للملف
If String.IsNullOrEmpty(searchTerm) Then
MessageBox.Show("يرجى إدخال كلمة البحث.")
Return
End If
If Not File.Exists(filePath) Then
MessageBox.Show("الملف النصي غير موجود.")
Return
End If
Dim content As String = File.ReadAllText(filePath)
Dim regexPattern As String = String.Format("\b(\w+)?\b\s+{0}\b", Regex.Escape(searchTerm))
Dim regex As New Regex(regexPattern, RegexOptions.IgnoreCase)
Dim matches As MatchCollection = regex.Matches(content)
Dim results As New Text.StringBuilder()
Dim count As Integer = matches.Count
For Each match As Match In matches
If match.Success Then
Dim previousWord As String = If(String.IsNullOrEmpty(match.Groups(1).Value), "", match.Groups(1).Value)
results.AppendLine($"{previousWord} {searchTerm}")
End If
Next
txtResults.Text = results.ToString()
txtCount.Text = count.ToString()
End Sub
End Class
شكرا أخي الكريم
و لكن من دون نتيجة
مثلا إذا كتبت كلمة المؤمنون في مربع البحث ستأتيك النتيجة هكذا :
سورة المؤمنون
فقط بدلا من يأتيك بكلمات المؤمنون الأخرى في القرآن الكريم
ثانيا عدد الكلمات = 1
ربي زدني علما 
