
27.05.2008, 19:34
|
|
Познающий
Регистрация: 02.02.2007
Сообщений: 78
Провел на форуме: 1514596
Репутация:
49
|
|
Вобщем, есть прога, которая считывает данные с текстового файла, надо чтобы пользователь вводил искомый текст, а выводило строку содержащую данный текст
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..
|
|
|