مرحا شباب
أنا بحاجةإلى برنامج يقوم بالبحث عن string داخل ملف نصي
ثم يقوم المستخدم بإدخال حرف أو string فيقوم البرنامج بالبحث عنه في الملف النصي
المشكلة التي واجهتني هي كيف أجعل البرنامج يقرأ الملف النصي حرف حرف ؟؟
حالياً البرنامج يقرأ الملف النصي كلمة كلمة ثم يخزنها في مصفوفة
هذا هو البرنامج
using System;
using System.Text;
using System.IO;
namespace Search_in_TextFile
{
class Program
{
static void Main()
{
Console.WriteLine("*************** TEXT ***************");
StreamReader sr = new StreamReader(@"c:\F.txt");
string line = sr.ReadLine();
while (line != null) // disply text from the file
{
Console.WriteLine(line);
line = sr.ReadLine();
}
Console.WriteLine("************************************");
string chose="no";
do
{
Console.Write("\nEnter Search Word :");
string s = Console.ReadLine();
Find String = new Find();
String.findString(s);
Console.WriteLine("\n************************************");
Console.Write("\nDo you want search another word ?<yeas,no):");
chose=Console.ReadLine();
Console.WriteLine("\n************************************");
}while(chose != "no"); // end loop
}
}
}
class Find
{
string NoResult;
string Result;
int count = 0;
public void findString(string word)
{
StreamReader sr = new StreamReader(@"c:\F.txt");
string line = sr.ReadLine();
while (line != null)
{
string[] array = line.Split(' ');
foreach (string w in array)
{
if (w == word)
{
Result = w;
count++;
NoResult = w;
}
}
line = sr.ReadLine();
}
if (Result != null)
{
Console.WriteLine("\nFound");
Console.WriteLine("\nNumber Of Find = " + count);
count = 0;
}
if (NoResult == null)
Console.WriteLine("\nNo Result");
}
}
أرجوا من لديه القدرة على المساعدة أن لا يبخل علينا وأكون له من الشاكرين
تحياتي
