Поиск слов в документе - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
private Form i;
private char sl;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
{
listBox1.Items.Clear();
string fold = textBox1.Text;
string[] files = Directory.GetFiles(fold);
string sl = textBox2.Text;
for (int i = 0; i < files.Length; i++)
{
string s = File.ReadAllText(files[i]);
if (s.IndexOf(sl) != -1)
{
string pos = s.IndexOf(s).ToString();
listBox1.Items.Add("\n"+files[i]);
}
}Решение задачи: «Поиск слов в документе»
textual
Листинг программы
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
string fold = textBox1.Text;
string[] files = Directory.GetFiles(fold);
string sl = textBox2.Text;
for (int i = 0; i < files.Length; i++)
{
string s = File.ReadAllText(files[i]);
if (s.IndexOf(sl) != -1)
{
string pos = s.IndexOf(s).ToString();
listBox1.Items.Add("\n"+files[i]);
}
}
if (ListBox1.Items.Count == 0)
{
listBox1.Items.Add("Cлов не найдено");
}
}