Вобщем, есть прога, которая считывает данные с текстового файла, надо чтобы пользователь вводил искомый текст, а выводило строку содержащую данный текст
Цитата:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введіть назву файла");
string fname = "c:\\" + Console.ReadLine();
Console.WriteLine("Введіть текст для пошуку");
string ftext = Console.ReadLine();
if (!File.Exists(fname))
{
Console.WriteLine("{0} не існує", fname);
}
using (StreamReader sr = File.OpenText(fname))
{
string input;
input = null;
int c = 0;
while ((input = sr.ReadLine()) != null)
{
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введіть назву файла");
string fname = "c:\\" + Console.ReadLine();
Console.WriteLine("Введіть текст для пошуку");
string ftext = Console.ReadLine();
if (!File.Exists(fname))
{
Console.WriteLine("{0} не існує", fname);
}
using (StreamReader sr = File.OpenText(fname))
{
string input;
input = null;
int c = 0;
while ((input = sr.ReadLine()) != null)
{
//////////////////////////////////////////////////////////////////
// КАК ЕГО ПРАВИЛЬНО ПРИЛЕПИТЬ СЮДА???
///////////////////////////////////////////////////////////////////
string z=input.IndexOf(ftext);//????
if ( ?????? )
{
Console.WriteLine(input);
}
}
Console.WriteLine(c);
sr.Close();
}
Console.ReadKey();
}
}
}
if (z==null)
{
Console.WriteLine(input);
}
}
Console.WriteLine(c);
sr.Close();
}
Console.ReadKey();
}
}
}
Последний раз редактировалось MaDfUn; 27.05.2008 в 19:36..
может ты хотел сказать если файл больше 5-10 мег ?
ну можно binaryreader , правда чуть больше гемора прибавится,
хотя ето наверна из методички какой то методы для студентов, наверно там подразумевается через ReadLine() тогда еще проще
Последний раз редактировалось 12usver12; 27.05.2008 в 23:22..
что-то вроде :
...
nput = null;
int c = 0;
while ((input = sr.ReadLine()) != null)
{
Код:
if ( input.indexOf("строка") > 0)
{
...
нашли совпадение
...
}
}...
Выдаёт ошибку:
Error 1 'string' does not contain a definition for 'indexOf' and no extension method 'indexOf' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) D:\Documents and Settings\Администратор\Мои документы\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplicati on2\Program.cs 31 31 ConsoleApplication2