منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
بدل ما اقوله اقرء الي في السطر كذا ... عايز اقوله إذا وجدت هذا السطر في اي مكان افعل - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : بدل ما اقوله اقرء الي في السطر كذا ... عايز اقوله إذا وجدت هذا السطر في اي مكان افعل (/showthread.php?tid=23094)



بدل ما اقوله اقرء الي في السطر كذا ... عايز اقوله إذا وجدت هذا السطر في اي مكان افعل - DanyGhost2010 - 27-12-17

ده كود لقرائة سطر في ملف تكست
الملف اسمه Boo.txt السطر مكتوب فيه open my file
انا مش عايز اقول له لو لقيت هذا السطر في السطر الاول او الثاني افعل كذا
انا عايز اقول له لو لقيت هذا السطر في اي مكان من ملف التكست افعل كذا

Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim objStreamReader As StreamReader
        Dim strLine As String

        'Pass the file path and the file name to the StreamReader constructor.
        objStreamReader = New StreamReader("C:\Boo.txt")

        'Read the first line of text.
        strLine = objStreamReader.ReadLine
        If strLine = "open my file" Then
            MsgBox(strLine)
        End If



        'Continue to read until you reach the end of the file.
        Do While Not strLine Is Nothing

            'Write the line to the Console window.
            Console.WriteLine(strLine)

            'Read the next line.
            strLine = objStreamReader.ReadLine
        Loop

        'Close the file.
        objStreamReader.Close()

        Console.ReadLine()
    End Sub


End Class


RE: بدل ما اقوله اقرء الي في السطر كذا ... عايز اقوله إذا وجدت هذا السطر في اي مكان افعل - طالب برمجة - 27-12-17

هذا تعديل للكود
PHP كود :
Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button1.Click
    Dim arr
() As String IO.File.ReadAllLines("C:\Boo.txt")
 
   If arr(1) = "open my file" Then
        MsgBox
("وجد في السطر الثاني")
 
   ElseIf arr.Contains("open my file"Then
        MsgBox
("وجد في الملف")
 
   Else
        MsgBox
("لا يوجد")
 
   End If
End Sub