03-04-18, 01:36 AM
(02-04-18, 03:23 PM)silverlight كتب : فيه أكثر من أسلوب للمقارنةبارك الله فيك
مثلا تقوم بقراءة الملفات و تحول كل منهما الي مصفوفة بايت ثم تقارن بين المصفوفات
حل أخر تقرأ الملفات و تحول كل ملف الي مصفوفة سطور ثم تقارت المصفوفات ايضا
في كلتا الحالات فكرة كتابة الكود واحدة
الحل الأول
PHP كود :
Dim firstFile As String = ".\File1.txt"
Dim secondFile As String = ".\File2.txt"
Dim a As Byte() = IO.File.ReadAllBytes(firstFile)
Dim b As Byte() = IO.File.ReadAllBytes(secondFile)
Dim result As Boolean = False
If a Is Nothing AndAlso b Is Nothing Then
result = True
ElseIf a IsNot Nothing AndAlso b IsNot Nothing AndAlso a.Length = b.Length Then
result = True
For i As Integer = 0 To a.Length - 1
If a(i) <> b(i) Then
result = False
Exit For
End If
Next
End If
حل أخر
PHP كود :
Dim firstFile As String = ".\File1.txt"
Dim secondFile As String = ".\File2.txt"
Dim c As String() = IO.File.ReadAllLines(firstFile)
Dim d As String() = IO.File.ReadAllLines(secondFile)
Dim result As Boolean = False
If c Is Nothing AndAlso d Is Nothing Then
result = True
ElseIf c IsNot Nothing AndAlso d IsNot Nothing AndAlso c.Length = d.Length Then
result = True
For i As Integer = 0 To c.Length - 1
If c(i) <> d(i) Then
result = False
Exit For
End If
Next
End If
